TestRunner Topics

Running Tests from the VB IDE

Running compiled tests from the command line

Using the Mini TestRunner

Running Tests from the VB IDE

Tests can be run by the vbUnit Add-In in compiled and in debug mode from within the VB IDE. To use the integrated IDE TestRunner, you need to set the debug mode of your project to start the program StartVBUnit:


Figure 1: Project Properties / Debug Startup Mode

If you use the Project Templates to create a new TestDll (as described in the tutorial), the startup mode is already set to load StartVBUnit.exe, so in that case you don't have to do anything. 
For instructions about how to use the IDE TestRunner Interface click here. You should also take a look at the vbUnit Options to find out how you can customize the behavior and appearance of the interface.

top

 

Running compiled tests from the command line

The file vbUnit3\bin\runTestSuite.bat contains an example of using the batch TestRunner: Just call RunVBUnit.exe with the ProgID of the TestSuite as argument. For example:

RunVBUnit TestVBUnitFramework.VBUnitTestSuite

You can also supply the ProgIDs of several TestSuites separated by spaces. In that case they will all be run. Here is the complete command line syntax for the Batch TestRunner:

Usage:
RunVBUnit [-tnal] TestSuite.ProgID [TestSuite1.ProgID] [TestSuite2.ProgID] [...]
                  [export Export1.ProgID [- "custom params"]] [...]
Options:
t - show the TestRunner Window
n - no output to the console!
a - don't autoclose TestRunner Window          
l - list incoming results in TestRunner

TestSuite.ProgID- load the indicated TestSuite and run it
export ExportModule.ProgID
[- "custom parameters"]
- load the indicated Export Module to process the TestResult
  optionally pass a custom parameter string

The return value of RunVBUnit is:
  0 : no errors, no failures
-n : n errors
 m : no errors, m failures

For example, 

RunVBUnit -ta TestVBUnitFramework.vbUnitTestSuite export ResultExport.XMLConverter

will run the unit tests of the vbUnit Framework, where the TestRunner window will show status information about the current test and remain open after the tests are finished. Further, it will load an export module that will write the test result to an XML file.

A more complex example can be found in the file vbUnit3\bin\runTestSuiteDemo.bat :

RunVBUnit -tla TestVBUnitFramework.vbUnitTestSuite 
                        TestResultExport.CallSampleTest 
    export ResultExport.XMLConverter - "..\ResultExport\Output\runTestSuiteDemo.xml" 
    export ResultExport.Logger - ..\ResultExport\Output\runTestSuiteDemo.log

This will run two test suites (vbUnitTestSuite and CallSampleTest), and it will export the results to an XML file (runTestSuiteDemo.xml), and to a logfile (runTestSuiteDemo.log). You can find those files in the vbUnit3\ResultExport\Output folder.

top

 

Using the Mini TestRunner

The vbUnit3 Professional TestRunner executes tests in their own process to avoid bringing down the IDE if a test crashes. This improves stability but can make it difficult to debug tests in some situations. Also, you may want to run tests on machines where the full vbUnit3 Professional distribution is not installed. For these cases, use the MiniTestRunner.

To see how it works, open the file vbUnit3\TestVBUnitFramework\MiniTestRunner\MiniTestRunner.vbg. In particular, take a look at sub main in MiniTestRunner.bas. It simply calls the test framework with the name of the suite to be executed and reports the results in a message box. To adjust this to your own tests, simply change the name of the suite to be run:

'MiniTestRunner.bas

Public Sub main()
Dim result As String
  Call runImmediately("TestVBUnitFramework.VBUnitTestSuite", result)
  Debug.Print result
  MsgBox result, , "Done"
End Sub

 

top