Nunit test case

Source: Internet
Author: User

1. Create a project
2. Reference nunit. framework and reference the. dll file you want to test.
3. Write a testCode
Let's take my example (vs2005 as an example ):
Everybody needs to install nunit first, what I install is NUnit-Net-2.0 2.2.7, its:Http://www.nunit.org/
(1) simple use case code:

Using system;
Using system. Collections. Generic;
Using system. text;
Using nunit. Framework;

Namespace demonunit
{
[Testfixture]
Public class testunit
{
Private int;
Private int B;
[Setup]
Public void startvalue ()
{
A = 1;
B = 2;
}
[Test]
Public void add ()
{
Int sum = A + B;
Assert. areequal (3, sum );

}
}
}
After running nunit, a green bar appears, proving that the test is successful.

(2) Test the method use case code in your own DLL file:
Using system;
Using system. Collections. Generic;
Using system. text;
Using nunit. Framework;
Namespace testnunit
{
[Testfixture]
Public class nunitstart
{

[Testfixturesetup]
Public void Init ()
{
Dal. sqlhelper. connstring = "Server = (local); uid = sa; Pwd =; database = test ;";
}
[Test]
Public void testgetsubjectdetaillist ()
{
Int num = Dal. Questionnaire. gettypelist (1). count;
Assert. areequal (4, num );

}


}
}

Dal is the dll I want to test. DLL file. sqlhelper is a class in the DLL file. data-related operations are mainly used as third-party components. You can find them online. questionnaire is a class file with the gettypelist (INT) method. The returned result is a collection, Dal. questionnaire. gettypelist (1 ). count is the number of records in the set.
Assert. areequal (4, num); "4" indicates the expected number of records, and num indicates the actual number of records.

This is a bit messy. Please forgive me.


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.