Simple Application of Automatic unit testing (nunit)

Source: Internet
Author: User

I learned some unit tests (nunit) over a period of time, but I still use them for small projects. I think it is easy to run unit tests on the interface. however, I recently learned some theories about unit testing. I know that a good unit test should be executed automatically instead of manually. in order to learn more professional, I also want to see thisCodeIn the end, Nant is involved. This tool has long been heard of, but it has never been used, and it has always been difficult to use. After all, it is used to IDE.
After learning about Nant, we found that this tool seems to be closely related to nunit. What's more interesting is that Nant implements project compilation in a task-based manner, the memory is not very large yet. After all, it is still a command line tool. compared with IDE compilation, it is better to be close to the dead state (compiling large projects ). nant tasks are all configured in an XML file. with simple configuration, You can execute n multi-objective compilation, and then execute otherProgram. Some may say that this is not batch processing. in theory, batch processing can also compile n multiple files, which is troublesome. however, Nant not only compiles a project, but also comes with many functions. If you study it in depth, you cannot learn it as a language.
Of course, a good unit test is only one of the conditions for automatic execution. In addition, a reasonable test case is needed, so we will continue to learn .............

The following is the content of *. Build File, automatically compile the main project and unit test project, and finally automatically execute unit test.

*. Build
1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < Project Name = "Myproject" Basedir = "." Default = "Run" Xmlns = "Http://nant.sf.net/release/0.85/nant.xsd" >
3 <! -- Configure the files of the main project and test project in sequence, and configure the path of the unit test file. -->
4 <! -- All file paths use the path *. Build as the root directory. -->
5 < Property Name = "Myproject. dir" Value = ". \ Myproject" />
6 < Property Name = "Myproject. bin" Value = "$ {Myproject. dir} \ bin" />
7 < Property Name = "Myproject. lib" Value = "$ {Myproject. dir} \ Lib" />
8 < Property Name = "Myprojecttest. dir" Value = ". \ Myprojecttest" />
9 < Property Name = "Myprojecttest. bin" Value = "$ {Myprojecttest. dir} \ bin" />
10 < Property Name = "Myprojecttest. lib" Value = "$ {Myproject. dir} \ Lib" />
11 < Property Name = "Nunit.exe" Value = ". \ Nunit \ nunit-console.exe" />
12 < Property Name = "Myprojecttest. nunit" Value = "Myprojecttest. nunit" />
13 <! -- Execute task -->
14 < Target Name = "Run" >
15 < Call Target = "Buildproject" />
16 < Call Target = "Buildprojecttest" />
17 < Call Target = "Runnunit" />
18 </ Target >
19 <! -- Compile the main project -->
20 < Target Name = "Buildproject" >
21 < Echo Message = "Building myproject" />
22 < Solution Configuration = "Debug" Outputdir = "$ {Myproject. Bin }" >
23 < Projects >
24 < Include Name = "$ {Myproject. dir} \ myproject. csproj" />
25 </ Projects >
26 < Assemblyfolders Basedir = "$ {Myproject. Lib }" />
27 </ Solution >
28 </ Target >
29 <! -- Compile a test project -->
30 < Target Name = "Buildprojecttest" >
31 < Echo Message = "Building myprojecttest" />
32 < Solution Configuration = "Debug" Outputdir = "$ {Myprojecttest. Bin }" >
33 < Projects >
34 < Include Name = "$ {Myprojecttest. dir} \ myprojecttest. csproj" />
35 </ Projects >
36 < Assemblyfolders Basedir = "$ {Myprojecttest. Lib }" />
37 </ Solution >
38 </ Target >
39 <! -- Execute unit test -->
40 < Target Name = "Runnunit" >
41 < Echo Message = "Executing nuni test" />
42 < Exec Program = "Zookeeper nunit.exe }" >
43 < ARG Value = "$ {Myprojecttest. nunit }" />
44 </ Exec >
45 </ Target >
46 </ Project >

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.