Create a simple unit test project

Source: Internet
Author: User

/* 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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.