From installation to configuration
First, go to http://www.nunit.org/to download the information and install the nunit-2.6.1.msipackage.
The tool is then used in VS2010 external tools. The tool is> external tool> Add> title: Nunit> command: installation path> OK.
Then open Nunit, tool-> Nunit.
VS2010 NUnit integration plug-in Visual Nunit 2010 download:
View in VS2010-> You Can See Visual Nunit in other forms (or press Ctrl + F7) to open the view and drag it to a proper position. If this function is enabled, the test method is automatically loaded.
Getting started
Create a project, for example (pay attention to project dependency and Assembly reference ):
//Number.csnamespace BaseClass{ public class Number { public static int TestMethod() { return 29; } }}
// NunitTestClass. csnamespace NunitTestClass {// <summary> /// initial-blog garden http://zxlovenet.cnblogs.com /// </summary> /// this is a test class [NUnit. framework. testFixture] public class NunberTest {// method used for testing // The method must be public and return type void. No parameter [Test] public void GetTestAreEqual () {int test1 = BaseClass. number. testMethod (); // verify that the value of test1 must be 29 to pass Assert. areEqual (29, test1);} [Test] public void GetTestGreater () {int test1 = BaseClass. number. testMethod (); // verify that the value of test1de must be greater than 0 to pass Assert. greater (test1, 30 );}}}
Then F6 is generated. Find the generated file, for example:
In VS2010, the tool-> Nunit, open File-> New Project ..., Save it to a location and click Fiel-> Save. Add Assembly: Project-> Add Assembly ..., Find the test file, for example:
Effect after opening
Click Run to Run the test. The result is as follows:
It can be seen that "√" is used for testing and "×" cannot be used for testing ".
Let's take a closer look at the layout of the testing runner window. In the middle of the right panel, you can see the test progress bar. The color of the progress bar reflects the test execution status:
L green description all tests currently passed
L yellow indicates that some tests are ignored, but none of them fail.
L red indicates a failure
The bottom status bar indicates the following status:
L status. It indicates the status of the current test. When all tests are Completed, the status changes to Completed. The status is Running: <test-name> (<test-name> is the name of the currently Running test ).
L Test Cases indicates the total number of Test Cases in the loaded assembly. This is also the number of leaf nodes in the test tree.
L number of Tests completed by Tests Run.
L Failures so far, the number of Failures in all tests.
L Time: display the test run Time (in seconds)
The File main menu has the following content:
L New Project allows you to create a New Project. A project is a set of test assembly. This mechanism allows you to organize multiple Test Sets and treat them as a group.
L Open loads a new test assembly or a previously saved NUnit project file.
L Close to Close the currently loaded test assembly or the now loaded NUnit project.
L Save the current Nunit project to a file. If you are working on a single assembly, this menu item allows you to create a new NUnit project and save it in a file.
L Save As allows you to Save an existing NUnit project As a file.
L Reload force Reload existing test assembly or NUnit project. NUnit-Gui automatically monitors changes to the currently loaded test assembly.
When the Assembly changes, the test runner reloads the test assembly. (When the test is running, the currently loaded test assembly will not be reloaded. The test assembly can only be reloaded during the test run. One piece of advice: if the test assembly depends on another assembly, the test runner will not observe any dependent assembly. For the test runner, force an overload to make all dependent assembly changes visible.
L Recent Files indicates five test assembly or NUnit projects recently loaded in NUnit (This list is maintained by each user in the Windows registry, So if you share your PC, you only see your test ). You can use the Options menu item to modify the number of recent Assemblies. You can access the Tool main menu.
L Exit.
L The View menu has the following content:
L Expand layer-by-layer expansion of the nodes selected in the tree
L Collapse fold the nodes selected in the tree
L Expand All nodes after the selected node in the recursive extension tree
L Collapse All recursively fold All nodes after the selected node in the tree
L Expand Fixtures all nodes in the extension tree that represent the test fixture.
L Collapse Fixtures: All nodes in the folding tree that represent the fixture test.
L Properties: displays the attributes of the selected node in the tree.
L the Tools menu consists of these items:
L Save Results as XML is used as an XML file to Save the test Results.
L Options allows you to customize NUnit behavior.
L now look at the right. You are familiar with the Run button and progress bar. There is also a Stop button that follows the Run button: clicking this button will terminate the running test. The following is a text window on the progress bar, which consists of the following four labels:
L The Errors and Failures window displays failed tests. In our example, the window is empty.
L The Tests Not Run window shows the Tests that have Not been executed.
L The Console. Error window displays the Error messages generated during the test. These messages can be output by the application code using the Console. Error output stream.
L The Console. Out window displays the text message of the output stream printed from the running test to the Console. Error.
References: http://confach.cnblogs.com/archive/2005/06/20/177817.aspx
Summary
NUnit has the following advantages:
1. Independent from IDE and can be run independently. You can also run the command line. (Can vs be used too ?)
2. Quick version updates. (I don't think this is an advantage, and I don't think it's quick .)
3. The UT tool of VS runs slowly. (Not necessarily)
NUite has the following Disadvantages:
1. Debug is not supported. It must be installed with TestDriven. NET.
2. Viewing code coverage is not supported. It must be used with NCover. VS code coverage is clear.
3. The test code cannot be automatically generated. It may be better to use it with CodeSmith, but it will be charged later.
I am in a bad mood. I will try to adjust my mood as soon as possible ~