This chapter describes how to install, test, and describe the Linux testing software Attribute.
I. Installation of Linux testing software Attribute
Free, open-source unit testing software.
You only need to run the installer according to all the default settings.
NUNIT: http://www.nunit.org/
Nunit addin: http://sourceforge.net/projects/nunitaddin/
Ii. Linux testing software DLL Testing
1: Create a Class Library PROJECT,
2: Add a reference to the DLL to be tested,
3: Add NUnit. Framework. dll reference
4: Add using NUnit. Framework to the beginning of the file.
5: before the class to be tested, add: [TestFixture]
6: Add [Test] before the method to be tested.
7: start the NUNIT-GUI, create a PROJECT, add and execute the new Class Library PROJECT.
Iii. Introduction to Linux testing software Attribute
1: TestFixture: This Attribute must be added before each class to be tested.
Note: The class to be tested must have a public default constructor (or no constructor is defined)
2: Test: This Attribute must be added before the function to be tested in each Test class.
Note: The method with Test attribute must be public, return void, and no input parameter. If these rules are not met, the method is not listed in the Test Runner GUI, and the method is not executed when the Unit Test is executed.
3: Introduction to TestFixtureSetUp and TestFixtureTearDown
These two functions are mainly used in TestFixture, which provides TestFixtureSetUP before a group of functions are executed for any test run) and TestFixtureTearDown after the last test is executed ). Each TestFixture can have only one TestFixtureSetUp method and one TestFixtureTearDown method. If you use more than one TestFixtureSetUp and TestFixtureTearDown methods, you can compile the method but do not execute it. Note that a TestFixture can have a TestFixtureSetUp and a SetUp, or a TestFixtureTearDown and a TearDown method.
TestFixtureSetUp and TestFixtureTearDown are not convenient to use the SetUp and TearDown methods.
Generally, SetUp and TearDown attributes are used.
4: Introduction to SetUp and Teardown Attributes
When writing Unit Tests, you sometimes need to make preparations or aftercare before or after each test method is executed. Of course, you can write a private method and call this special method at the beginning or end of each test method. Alternatively, you can use the SetUp and Teardown Attributes we will introduce to achieve the same purpose. As these two Attributes names mean, the method with SetupAttribute will be executed by test Runner before each Test method in the TextFixture is executed, methods With Teardown Attribute are executed by test Runner after each Test method is executed. Generally, Setup Attribute and Teardown Attribute are used to prepare required objects (objects), such as database connection.
5: Attribute description
TestFixture: This Attribute must be added before each class to be tested.
Test: This Attribute must be added before the function to be tested in each Test class.
TestFixtureSetUp: run only once in a test class and before running all test cases
SetUp: Run before each test case
ADD: Test Case 1
TearDown: Run after each test case
SetUp: Run before each test case
Sub: Test Case 2
TearDown: Run after each test case
TestFixtureTearDown: runs only once in a test class and after all test cases are run.
ExpectedException: detects and throws an exception.
[Test]
[ExpectedException (typeof (InvalidOperationException)]
[Test, ExpectedException (typeof (InvalidOperationException)]
Ignore: temporarily Ignore some tests
Ignore ("Not ready to test this yet ");