The following script is generated by importing NUnit Money and selecting the three methods BagMultiply, BagNegate, and BagSimpleAhdd.
transaction TInit var sFileName : string; begin DotNetSetOption(DOTNET_OPT_REDIRECT_CONSOLE, 1); // ============================================== // Unit Test TestClass Information: // Used Framework: NUnit Test Framework // Initialize method: SetUp // Class contains 21 test methods! // ============================================== GetDataFilePath("nunitmoneysample.dll", sFileName); ghTestObj := DotNetUnitTestLoadObject(sFileName, "NUnit.Samples.Money.MoneyTest", "NUnit.Samples.Money.MoneyTest"); end TInit; transaction TMain begin // BagMultiply DotNetUnitTestCallMethod(ghTestObj, "BagMultiply", "BagMultiply"); // BagNegate DotNetUnitTestCallMethod(ghTestObj, "BagNegate", "BagNegate"); // BagSimpleAdd DotNetUnitTestCallMethod(ghTestObj, "BagSimpleAdd", "BagSimpleAdd"); end TMain; transaction TEnd begin DotNetUnitTestFreeObject(ghTestObj, "NUnit.Samples.Money.MoneyTest"); end TEnd;
DotNetUnitTestLoadObject loads the NUnit assembly and creates an instance of the test class. If the test class has a global initialize function implemented (marked with TestFixtureSetup - ClassInitialize), this function will be called right after the object is created.
DotNetUnitTestFreeObject in the TEnd transaction frees the reference to the test object. If the test class has a global uninitialize function implemented (marked with TestFixtureTearDown - ClassCleanup), this function will be called prior to release of the object.
DotNetUnitTestCallMethod calls the TestMethod in the same way that the NUnit Microsoft Unit Test Engine does. If there is a SetUp - TestInitialize method implemented, it will be called before the test method is called.
If there is a TearDown - TestCleanup method implemented, it will be called after the test method is called.
Test methods that expect an exception to be thrown (those marked with ExpectedException) are only considered successful when an exception is actually thrown.
When a test method writes information to the error or out console, the information can be viewed in the TrueLog. A separate element is logged as child node of the DotNetUnitTestCallMethod.
The same applies for unexpected exceptions. Stack trace and exception messages are logged to the TrueLog.
A new optional timer parameter has been introduced for the original DotNet API calls and the new DotNetUnitTest API calls. When this parameter is specified, the execution times of the constructor, test method, set up method, and tear down method are measured. For the example above you would receive the following measures: