C # Unit Test NUnit Summary (20141018)

Source: Internet
Author: User

1. Download and install the NUnit tool:

NUnit is an open source regression testing framework that is similar to JUnit, for. NET developers to do unit testing, can be obtained from the www.nunit.org website free of charge, and then installed in the system;

2, in the VS2010 to do the configuration:

? Select "Tools"-"External tools ..."

? Click "Add" to fill in the names in < title > and < Command > and specify the EXE to be launched by the external tool.

? Under Tools, you can see the external tool "Nunit2.6" just added to the configuration, and you can start the NUnit directly with VS here.

3, the general process of unit testing:

? The items and functions being tested

? Create a new project as a test project

? Generally we create a new test project, select the class library is enough, the name of the project tested with test;

? Here, we directly rename the generated class to the class being tested, and the unit test cases that are done by the method of the test class can be placed in this test class

? We first need to refer to the tested assembly and NUnit in the test project Framwork

? References to the assembly under test

? References to NUnit Framwork

When we're done, we can see the following references to the test project:

? Adding "Using Nunit.framework" to the test class

? To design and write unit test cases, we need to be aware that:

2 We are using the NUnit framework, so in the test class we need to add [testfixture] and [test] to indicate that this is a test class and a test method

2 The return type of the test method must be void, the method argument is empty

2 In addition, we can use properties to do some control, so that more flexible

2 using Assert assertions to compare expected and actual results

? Build the test project (that is, the compilation we say)

? Open the NUnit tool with VS, "tools"--"Nunit2.6"

? Create a new project, "File"--"new project ..."

? Select path and fill in name

? In the project, add the test assembly, "project"--"add Assembly ..."

We can see three assemblies, the assembly being tested, the test assembly, and the Nunitframework

? The Nunit tool shows the same as the unit test cases we designed

? After running we can see the test results, red indicates failure, yellow indicates not running, green means through

2 Results of the failure

2 Ignore non-running results

C # Unit Test NUnit Summary (20141018)

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.