/* By garcon1986 */
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 <1, 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.
Hope this helps. Enjoy coding!