XUnit Testing Tools

Just collect some document here, for convenience. Maybe will do some illustration later.

Java:

* TestNG document  from testng.org
* Junit  document from junit.org

.Net:

* NUnit  review in CSDN blog

[JUnit Usage]:
1.TestCase
java.lang.Object
|
+--junit.framework.Assert
|
+--junit.framework.TestCase
1) implement a subclass of TestCase
2) define instance variables that store the state of the fixture
what is fixture:
..Create a subclass of TestCase
..Create a constructor which accepts a String as a parameter and passes it to the superclass.
..Add an instance variable for each part of the fixture
..Override setUp() to initialize the variables
..Override tearDown() to release any permanent resources you allocated in setUp
3) initialize the fixture state by overriding setUp
4) clean-up after a test by overriding tearDown.
5)Write the test case method( testXXXX() ) in the fixture class. Be sure to make it public, or it can't be invoked through reflection.
6)Create an instance of the TestCase class and pass the name of the test case method to the constructor.

2.TestSuite

1)TestSuite suite = new TestSuite();
2)suite.addTestSuite(XXX.class); || suite.addTest(new XXX("xxx"));
3)suite.run();

3.TestRunner

1)tesxtual: fastest, when don't need red green success indication.
java.lang.Object
|
+--junit.runner.BaseTestRunner
|
+--junit.swingui.TestRunner
2)Graphical: provide graphical progress indication. can be configure to  be either LOADING (reload class each time) or NON-LOADI
java.lang.Object
|
+--junit.runner.BaseTestRunner
|
+--junit.awtui.TestRunner
|
+--junit.textui.TestRunner

[Nunit usage]

1.Setup
..download the NUnit-2.2.7-net-2.0.msi at Nunit.org
http://www.nunit.org/index.php?p=download
..After setup will see a "Nunit-GUI" item in ProgrammeList

2.Create a C# project.Use 'Class Library' template e.g.
(1) neen add nunit.framework to References
(2) using NUnit.Framework;
(3) A simple example to get started here:

using NUnit.Framework;
namespace TestNunit
{
[TestFixture]
public class NumberFixture
{
[Test]
public void AddTwoNumbers() {
int a = 1;
int b = 2;
int sum = a + b;
Assert.AreEqual(sum,3);
}
}
}

.something about the attributes
..TestFixtureAttribute (NUnit 2.0)
-This is the attribute that marks a class that contains tests and, optionally, setup or teardown methods.
-It must be a publicly exported type or NUnit will not see it.
-It must have a default constructor or NUnit will not be able to construct it.

..TestAttribute  (NUnit 2.0)
-The Test attribute marks a specific method inside a class that has already been marked as a TestFixture, as a test method.
-The signature for a test method is defined as follows: public void MethodName() Note that there must be no parameters. If the programmer marks a test method that does not have the correct signature it will not be run and it will appear in the Test Not Run area in the UI that ran the program.

..SetUpAttribute (NUnit 2.0)
-performed just before each test method is called. A TestFixture can have only one SetUp method. If more than one is defined the TestFixture will compile successfully, but its tests will not run.

[SetUp] public void Init()
{ /* ... */ }
..TearDownAttribute (NUnit 2.0)
-performed after each test method is run. Similar with SetUpAttribute.

[TearDown] public void Dispose()
{ /* ... */ }
..SuiteAttribute (NUnit 2.0)
namespace NUnit.Tests
{
using System;
using NUnit.Framework;

public class AllTests
{
[Suite]
public static TestSuite Suite
{
get
{
TestSuite suite = new TestSuite("All Tests");
suite.Add(new OneTestCase());
suite.Add(new Assemblies.AssemblyTests());
suite.Add(new AssertionTest());
return suite;
}
}
}
}
..see more attributes here.http://www.nunit.org/index.php?p=attributes&r=2.2.7

(4)Save All Project,and build it.
3 .Run "NUnit-GUI", create a new nunit project.open the .dll file for the c# project.
the path shld be : urProject/obj/release/XXX.dll
press button <Run> and we can see the result.