One of the tools used in the project (nunit)

Source: Internet
Author: User

The current project will be used for daily build, and will use cruisecontrol. Net; but also for UT and nunit. So I learned about nunit usage over the weekend.

 

Nunit is actually a helper class library, through which you can test the writtenCodePut it in that framework and run it completely. That is to say, a "unit" is taken out, and a starting and ending is added. There is also a graphical interface (of course this can be used ). Sometimes some third-party tools, such as testdriven. net, are used to combine nunit with.

 

Even in the object-oriented programming mode, the basic unit of Ut is also a function, instead of ut in the unit of class. The public method can be called directly. How can we test the private and protected methods? Of course, it can also be solved, but it is more troublesome.

 

Using nunit allows you to directly call a separate code block in a test code without including the entire project. You don't need to close anything like the main entry.

 

Step 1: Install nunit. The latest version is 2.5.5. Download a zip package from the official website, decompress it, and place it anywhere. There is a bin folder, which has two types: one is used. net1.1, which is used. net2.0, since there is no third type, the description. the following content of net2.0 also applies. net3.5 ,. net4.0.

Step 2: open a vs project, select a CS file as the test object, and create another CS file to write the test code. Using nunit. framework is required first. Then add reference. Specify the nunit. Framework. dll under. net2.0 in the decompressed folder. Next, we use attribute to mark the code block for nunit recognition. Compile it.

Step 3: open the file named "nunit.exe" under "net2.0"ProgramThen, file-> open project, locate the. exe file compiled by the CS file of the test target, open it, and click the run button on the right to start the test.

 

If testdriven. NET is downloaded and installed, it is a vs plug-in. The test is more convenient. Go directly to the test code page, right-click it, and you will have a run test option. Click it and you will be able ...... Finally, an output window returns the result of your run. You can also track the test code in one step, which is very convenient.

 

There is a famous book about nunit: Unit Testing C #-use nunit.

 

In addition, after testdriven is installed, a tool named ncoverage will be attached. You can see the code coverage during your test, but it only counts the code coverage, rather than the path coverage. This tool is very convenient. If no code is run, it will be located at once.

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.