NUNIT unit test software for use
NUNIT Use
1: Software and Installation
Free, open source unit testing software.
Installation Just run the installer, you can press all the default settings.
NUNIT: www.nunit.org
NUNIT ADDIN: http://sourceforge.net/projects/nunitaddin/
2: DLL Test
1: Create a new Class Library PROJECT,
2: Add reference to DLL to be tested,
3: Add a reference NUnit.Framework.dll
4: In the beginning of the file by adding: using NUnit.Framework
5: Test the class to be added before: [TestFixture]
6: Test methods to be added before: [Test]
7: Start NUNIT-GUI, new projects, new Class Library PROJECT will join the Executive.
3: Attribute Description
1: TestFixture: before each class to be tested must be added to the Attribute.
【Note】 When the need for a public test class's default constructor (or does not define any constructor)
2: Test: Test the class of each test function to be added before the Attribute.
【Note】 a Test attribute of the method must be public and must return void, and no incoming parameters. If you do not meet these requirements, the Test Runner GUI is not listed among this method, and when in the implementation of the Unit Test will not run this method.
3: TestFixtureSetUp and TestFixtureTearDown Introduction
The two mainly used in TestFixture inside, its role is to provide a set of functions to perform any test run before (TestFixtureSetUP) and after the implementation of the final test (TestFixtureTearDown). Each TestFixture only one TestFixtureSetUp methods and TestFixtureTearDown method. If more than one TestFixtureSetUp and TestFixtureTearDown method, you can compile but not run. Note that one can have a TestFixtureSetUp TestFixture and a SetUp, can also have a TestFixtureTearDown and a TearDown method.
TestFixtureSetUp and TestFixtureTearDown be used in difficult to use SetUp and TearDown methods.
General use SetUp and TearDown attributes.
4: SetUp and Teardown Attributes Description
When writing Unit Tests, sometimes you will need to implement each test method before (or after) to make some preparatory or remedial work. Of course, you can write a private of the method, and then each test method in the beginning or very end of a call to this particular method. Or, you can use the we have to introduce the SetUp and Teardown Attributes to achieve the same purpose. As these two Attributes of the name means, the method will have Setup Attribute in the TextFixture Each test method is executed before the execution was Test Runner, while Teardown Attribute of method in each test method will be executed was performed after Test Runner. In general, Setup Attribute and Teardown Attribute must be used to prepare some of the objects (objects), such as database connection, and so on.
5: Attribute Description
TestFixture: before each class to be tested must be added to the Attribute.
Test: Each test class to be added before the function test of the Attribute.
TestFixtureSetUp: in a test class only once, and run all the test cases before the implementation of the
SetUp: before running each test case execution
ADD: Test Case 1
TearDown: After running each test case execution
SetUp: before running each test case execution
Sub: test case 2
TearDown: After running each test case execution
TestFixtureTearDown: in a test class only once, and after the implementation of all the test cases run
ExpectedException: detection of an exception
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Test, ExpectedException (typeof (InvalidOperationException))]
Ignore: temporarily ignore some tests
Ignore ("Not ready to test this yet");
4: NUNIT various assertions
Assertions are used to help you determine if a test function is working correctly, usually a test method will be more than assertion, when an assertion fails, the test method will be terminated. Call use Assert or Assertion assertion function.
1: AreEquals (expected, actual [, string message])
Expected is the expected value of the code being tested, actual is the actual value of the tested code, message is an optional message, the value of the two inconsistent reporting errors. Expected and actual can be an object.
For floating-point comparison, using AreEquals (expected, actual, tolerance [, string message]), which, tolerance, said precision that only a relatively small number of 0.01 after the two.
2: IsNull / IsNotNull (object [, string message])
Determine an object is empty / not empty.
3: AreSame (expected, actual [, string message])
Expected and actual judge whether the same object.
4: IsTrue (bool condition [, string message]) / IsFalse
Determine whether the condition is true / false.
5: Fail ([string message])
To test immediately be invalidated.
5: Exception Handling
NUNIT framework can catch any exception, and it reports an error, they do not require user involvement
6: Test preparation
NUNIT use of assertions to be tested to judge the industry code is to return the correct result, the process of preparing test cases, we often need to have a correct value as the basis and testing the code to return the value for comparison. In some cases, may be easier to get to the correct value, but sometimes to get the correct value is not easy. Such as taking data from the database, difficult to set a correct value, in this case, it is best to use some already being tested is correct or commercial module program to bring these tested procedures for the return value or commercial module as the correct value, as a comparison reference.
1: Software and Installation
Free, open source unit testing software.
Installation Just run the installer, you can press all the default settings.
NUNIT: www.nunit.org
NUNIT ADDIN: http://sourceforge.net/projects/nunitaddin/
2: DLL Test
1: Create a new Class Library PROJECT,
2: Add reference to DLL to be tested,
3: Add a reference NUnit.Framework.dll
4: In the beginning of the file by adding: using NUnit.Framework
5: Test the class to be added before: [TestFixture]
6: Test methods to be added before: [Test]
7: Start NUNIT-GUI, new projects, new Class Library PROJECT will join the Executive.
3: Attribute Description
1: TestFixture: before each class to be tested must be added to the Attribute.
【Note】 When the need for a public test class's default constructor (or does not define any constructor)
2: Test: Test the class of each test function to be added before the Attribute.
【Note】 a Test attribute of the method must be public and must return void, and no incoming parameters. If you do not meet these requirements, the Test Runner GUI is not listed among this method, and when in the implementation of the Unit Test will not run this method.
3: TestFixtureSetUp and TestFixtureTearDown Introduction
The two mainly used in TestFixture inside, its role is to provide a set of functions to perform any test run before (TestFixtureSetUP) and after the implementation of the final test (TestFixtureTearDown). Each TestFixture only one TestFixtureSetUp methods and TestFixtureTearDown method. If more than one TestFixtureSetUp and TestFixtureTearDown method, you can compile but not run. Note that one can have a TestFixtureSetUp TestFixture and a SetUp, can also have a TestFixtureTearDown and a TearDown method.
TestFixtureSetUp and TestFixtureTearDown be used in difficult to use SetUp and TearDown methods.
General use SetUp and TearDown attributes.
4: SetUp and Teardown Attributes Description
When writing Unit Tests, sometimes you will need to implement each test method before (or after) to make some preparatory or remedial work. Of course, you can write a private of the method, and then each test method in the beginning or very end of a call to this particular method. Or, you can use the we have to introduce the SetUp and Teardown Attributes to achieve the same purpose. As these two Attributes of the name means, the method will have Setup Attribute in the TextFixture Each test method is executed before the execution was Test Runner, while Teardown Attribute of method in each test method will be executed was performed after Test Runner. In general, Setup Attribute and Teardown Attribute must be used to prepare some of the objects (objects), such as database connection, and so on.
5: Attribute Description
TestFixture: before each class to be tested must be added to the Attribute.
Test: Each test class to be added before the function test of the Attribute.
TestFixtureSetUp: in a test class only once, and run all the test cases before the implementation of the
SetUp: before running each test case execution
ADD: Test Case 1
TearDown: After running each test case execution
SetUp: before running each test case execution
Sub: test case 2
TearDown: After running each test case execution
TestFixtureTearDown: in a test class only once, and after the implementation of all the test cases run
ExpectedException: detection of an exception
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Test, ExpectedException (typeof (InvalidOperationException))]
Ignore: temporarily ignore some tests
Ignore ("Not ready to test this yet");
4: NUNIT various assertions
Assertions are used to help you determine if a test function is working correctly, usually a test method will be more than assertion, when an assertion fails, the test method will be terminated. Call use Assert or Assertion assertion function.
1: AreEquals (expected, actual [, string message])
Expected is the expected value of the code being tested, actual is the actual value of the tested code, message is an optional message, the value of the two inconsistent reporting errors. Expected and actual can be an object.
For floating-point comparison, using AreEquals (expected, actual, tolerance [, string message]), which, tolerance, said precision that only a relatively small number of 0.01 after the two.
2: IsNull / IsNotNull (object [, string message])
Determine an object is empty / not empty.
3: AreSame (expected, actual [, string message])
Expected and actual judge whether the same object.
4: IsTrue (bool condition [, string message]) / IsFalse
Determine whether the condition is true / false.
5: Fail ([string message])
To test immediately be invalidated.
5: Exception Handling
NUNIT framework can catch any exception, and it reports an error, they do not require user involvement
6: Test preparation
NUNIT use of assertions to be tested to judge the industry code is to return the correct result, the process of preparing test cases, we often need to have a correct value as the basis and testing the code to return the value for comparison. In some cases, may be easier to get to the correct value, but sometimes to get the correct value is not easy. Such as taking data from the database, difficult to set a correct value, in this case, it is best to use some already being tested is correct or commercial module program to bring these tested procedures for the return value or commercial module as the correct value, as a comparison reference.
Nhận xét
Đăng nhận xét