Custom blockchain development company in USA

Custom blockchain development company in USA

Writing Tests - Quick Reference

Test Project

Fixtures and TestMethods

Messages

Suites

Test Project

A test project exposes one or more test suites that can be called by the TestRunner or some other program. Test projects must be of type ActiveX DLL to allow the automatic extraction of test methods from the fixture classes. You can quickly create a new Test Project with the project template called "vbUnit TestDll". Read the vbUnit tutorial for more information about how to set up a test project.

top

 

Fixtures and TestMethods

A fixture is a class that contains a setup of objects against which to run one or more tests. To create an empty fixture, use the class template for a "vbUnit TestFixture" (as described in the tutorial), or create a new class and add the following code:

'TestError

Public Sub TestError()
  Dim a As Long
  m_assert.Trace "this will throw an error"
  a = 5 / 0
End Sub
This will produce:

vbunitTestFixture.TestError : Division by zero : this will throw an error

top

 

Messages

You can send messages to the TestRunner window with m_assert.PrintMsg "some message". These messages are purely for the benefit of the human who looks at the TestResult and have no influence on the success or failure of a test.
Messages must be enabled with m_assert.EnablePrintMsg, which can be placed anywhere inside a TestMethod, or in the Setup or Create methods of a fixture. This allows to quickly turn messages on or off for any given fixture, since messages should only be used during development. When a fixture is stable, you should disable the messages by commenting out the EnablePrintMsg line to prevent cluttering your test result with too much information.

If you want to be able to double-click on a message to highlight the corresponding code line and your message uses a string expression instead of a literal string, you can supply an optional second parameter as a unique marker. This is purely for the code highlighting feature and won't show in the TestResult:

m_assert.PrintMsg "The counter is: " & counter, "countMsg1"

top

 

Suites

A suite contains one or more fixtures and exposes them to the TestRunner or any other program. Test suites can also contain other test suites. To create a new suite, use the class template for a "vbUnit TestSuite", or create a new empty class and add the following code. Then change the fixture names to match your fixture classes.

'NewTestSuite.cls

Option Explicit

Implements ISuite

Private Function ISuite_Suite() As ITest
Dim suite As New TestSuite
   suite.SuiteName = "New Test Suite"
   
   'add Test Fixtures here
   suite.AddFixture New Fixture1
   suite.AddFixture New Fixture2
   ' and so on ...
   
   'this is how to add other Test Suites
   suite.AddSuite New OtherLocalSuite
   suite.AddSuite CreateObject("OtherProject.RemoteTestSuite")

   Set ISuite_Suite = oSuite
End Function

top