Unit Test Tool NUnit

Source: Internet
Author: User
Tags xunit

I. Introduction to NUnit

NUnit is a unit test framework specifically for. NET. In fact, in front of JUnit (Java), CPPUnit (C ++), they are all part of xUnit. Initially, it came from JUnit, and the current version is 2.2.what I will use is based on this version. NUnit was initially developed by James W. Newkirk, Alexei A. Vorontsov and Philip A. Craig, and later the development team grew bigger. In the development process, Kent Beck and Erich Gamma also provide a lot of help. NUnit is the 4th main product in the xUnit family. It is fully written in the C # language and fully utilizes many. NET features, such as reflection and customer attributes .. The most important thing is that it is suitable for all. NET languages.

NUnit Official Website: http://www.nunit.org, readers who need to know the history and download the latest version can log on to its official website. This article describes how to use NUnit 2.6.


Ii. NUnit application in. NET

2.1. Shows the NUnit GUI layout)

650) this. width = 650; "style =" width: 731px; height: 452px "title =" 1.jpg" src = "http://www.bkjia.com/uploads/allimg/131228/2025331346-0.jpg" width = "1364" height = "594"/>

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:
  • Green:Indicates that the test has passed;

  • Yellow:Indicates that some tests are ignored;

  • Red:Indicates that the test failed;

The bottom status bar indicates the following status:
  • Status. Shows the status of the current test. The status changesCompleted;

    Running the test, the status isRunning:<Test-name> (<Test-name> Is the name of the running test ).

  • Test Cases:Describes the total number of test cases in the loaded assembly. This is also the number of leaf nodes in the test tree.

  • Tests Run:Number of completed tests.

  • Failures:The number of failed tests so far.

  • Time:Displays the testing time in seconds)

The File main menu has the following content:
  • New Project:Allow 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.

  • Open:Load a new test assembly or a previously saved NUnit project file.

  • Close:Disable the currently loaded test assembly or the currently loaded NUnit project.

  • Save: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.

  • Save:Allows you to save an existing NUnit project as a file.

  • 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.
  • Recent Files:Note that the list of five recently loaded test assembly or NUnit projects in the Windows registry is maintained by each user. Therefore, 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.

  • Exit:Exit.

The View menu has the following content:

  • Expand:Layer-by-layer scaling of nodes selected in the tree

  • Collapse:Fold the selected node in the tree

  • Expand All:All nodes after the selected node in the recursive extension tree

  • Collapse All:Recursively fold all nodes after the selected node in the tree

  • Expand Fixtures:All nodes in the extension tree that represent the test fixture.

  • Collapse Fixtures:Collapse all nodes in the tree that represent the fixture test.

  • Properties:Displays the attributes of the selected node in the tree.

The Tools menu has the following content:

  • Save Results as XML:Save the test result as an XML file.

  • Options:Let you customize NUnit behavior.

Now let's 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:
  • Errors and Failures:The window shows failed tests.

  • Tests Not Run:The window shows the tests that have not been executed.

  • Text Output:The running test is printedConsole. ErrorThe text message of the output stream.

Integrated into VS 2010 for testing

650) this. width = 650; "style =" width: 633px; height: 411px "title =" 2.jpg" src = "http://www.bkjia.com/uploads/allimg/131228/20253313G-1.jpg" width = "959" height = "492"/>

With the settings shown in the figure, nunit.exe is automatically started every time we press f5 runtime to load and generate

To test the DLL or EXE file. You can click "1" and then click "1" to manually start nunit.exe.

2.2 Introduction to common attributes

  • TestFixture

    Identifies a class, indicating that this class may contain methods used for testing.

  • Test

    Used to identify a method, indicating that this method needs to be tested.

  • SetUp

It is used to identify the method and run before all tests are started. It is used to initialize some resources before the test, such as initialization classes.

  • TearDown

It is used to identify the method and run after all tests are completed to release some resources.

  • Ignore

Identifies a method, indicating that the method does not need to be tested for some reason, for example, the related code is not completed.

For more information about other properties, see: http://www.36sign.com/nunit/index.html


This article is from the "memory of Growth" blog, please be sure to keep this source http://zhanyah.blog.51cto.com/2821907/1263728

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.