/*by Jiangong SUN*/
Unit test is used widely used in projects, it facilitates a lot the work of developers. Test Driven Development is a very popular development method based on unit testing.
There are some popular unit testing tools like xUnit (based on NUnit) etc. Visual studio has its own unit test "Microsoft.VisualStudio.TestTools.UnitTesting.Web"
Here I will create a simple unit test project.
Firstly, create a class library "BankSystem" with a class "IncomeMoney". Then, create a test project "UnitTest" with a test class "BankSystemTest".
Add a reference of BankSystem in project UnitTest.
Here is the structure of solution:
Create a property and a method in class "IncomeMoney"
namespace BankSystem
{
public class IncomeMoney
{
public decimal currentVolume
{
get;
set;
}
public bool IsAcceptable(decimal m)
{
if (m < 1000)
{
return true;
}
else
{
return false;
}
}
}
}
Create test method for testing if it's acceptable in the bank system
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BankSystem.UnitTest
{
[TestClass]
public class BankSystemTest
{
[TestMethod]
public void TestInputMoney()
{
IncomeMoney im = new IncomeMoney();
im.currentVolume = 1001;
im.IsAcceptable(im.currentVolume);
Assert.IsTrue(im.IsAcceptable(im.currentVolume));
}
}
}
Because current volume is "1001", it's larger than "1000". The test is failed.
You can download the code here: http://download.csdn.net/detail/garcon1986/4869222
Hope this helps. Enjoy coding !