[Nunit entry series lecture 1] nunit installation and function Introduction

Source: Internet
Author: User

Author: shinoy
Time: All rights reserved on February 8,. infringement is required.
Source: http://blog.csdn.net/snowshinoy

Nunit is an open-source. NET platform-based xunit white-box testing architecture that supports all. Net platforms. This architecture features open source, easy to use, and complete functions. It is a white-box testing framework suitable for product modules developed in. NET language. We can also expand this architecture to form a more advanced white box testing architecture suitable for ourselves. In this series, we will begin from the most basic installation to the application in the actual project, and gradually unveil the nunit.

I. Download and install nunit official homepage is http://www.nunit.org/index.php? P = home. We can find the download location. Doc is the relevant document. Here we download the MSI installation package and start the installation.


Ii. operation and function Introduction

You can find nunit in the Start Menu.

Run nunit to view the main interface

The following is a brief introduction to each functional area:

1. nunit toolbar: All nunit functions can be executed here. The main functions are to create/open a project, set the project execution configuration, and add test components for the project.

2. Test tree: All tests included in the current nunit project are shown here. There are two display modes: one is Display Based on the namespace structure and test set defined in the test code. Another way is to define similar test projects as the same category in the test code based on the category display, so that the same type of test can be put together for execution in this display mode.

3. test execution: You can control the run and stop of the test, and the progress of the test set of the current project is displayed.

4. Error display: when the test fails, the error cause and related information are displayed here.

5. Log window: This window will display log information in the test, mainly including some exceptions and error information, text output of the test and test code that are not run.

In addition, there is a status bar that displays the current running status and the total number of cases in the project at the bottom.

3. Deploy, generate, and test nunit. After nunit is installed, we can deploy it in our project to generate our test. How to deploy nunit in a project? Generally, the white box test will not change the project function code, but create a test project for this test separately. We only need to reference nunit construction in this project, and we can use it. Next we will generate our first test step by step. In Visual Studio, we create an empty project and add a reference to the nunit component. nunit can load DLL or EXE components. We create a project of this type. Add the nunit component reference for this project. Here I have installed two or more nunit installation packages, so we can see that there are two types of components available, when using this tool, you must note that the added version is the version you need. For details about the differences between different versions, refer to the instructions on the official website. Enter the following code in mytest. it doesn't matter if some attributes in the CS file are not understood for the moment. We will explain them in detail in subsequent lectures. Isn't it a sense of accomplishment to let our first test run first? Start!
using System;using System.Collections;using NUnit.Framework;namespace MyFirstTest{    /// <summary>    /// This is our first Nunit test    /// </summary>    [TestFixture]    public class MyTest    {        [Test]        public void Test1()        {            Console.WriteLine("Test1 Pass");        }        [Test]        public void Test2()        {            Console.WriteLine("Test2 Fail");            Assert.Fail();        }        [Test]        public void Test3()        {            Console.WriteLine("Test3 Ignore");            Assert.Ignore();        }    }}
Note This sentence
using NUnit.Framework;

This statement declares the nunit namespace, and we can use nunit in our code. This step is indispensable for adding reference. Now we can compile our test project and generate a file named myfirsttest. dll, which is our test component. You can use nunit to load and run it. Now we can run our test. Please refer to the running result of this test.

In this test, we define a successful test test1, a failed test Test2, and a skipped test test3. In the test set tree, different test results are displayed with different icons. The error area on the right shows the failed cases and some test statistics. The log area in the lower-right corner shows the line in which the error is generated during the test to facilitate debugging after the test. In addition, you may notice that some information is output in each test code. Where should this information be displayed? By the way, it is very convenient under the text output label. We can output more information in the test code to facilitate our observation.

So far, we have deployed and run our first nunit-based test. Isn't it easy? I also want to remind you that nunit supports the latest. Net framework4. For different CLR versions, we need different runtime environments. First, set the CLR version of our test project. In vs, select the application attribute and select the desired version.

Here we chose. NET Framework 3.5. in nunit, we can switch the runtime environment to. Net framework4 (compatible with 3.5.

Iii. Summary This article is here. We have gone through the first nunit test from installation to running. nunit has more features than that, of course, later we will have more functions and skills introduction, please continue to pay attention to this series of courses, if you do not understand the problem of the course, you can mail me 28345697@qq.com, thank you. White box test QQ chat group:

RSS subscribes to iquicktest (how to subscribe ?)

Googlereader subscribe address: http://feeds.feedburner.com/iquicktest

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.