Skip to content

How‐to: Build a simple unit test

Josef Pötzl edited this page Sep 1, 2024 · 2 revisions
  1. Create a new class module
  2. Mark the class as a test class with the comment text 'AccUnit:TestClass
  3. A public sub in this class is passed as a test
  4. The public sub Setup can be used as test preparation. This is called before each test.
  5. Public sub Teardown is run after each test.

Example test class

Option Compare Database
Option Explicit

'AccUnit:TestClass

Public Sub Setup()
' This procedure is called before each test
End Sub

Public Sub Teardown()
' This procedure is called after each test
End Sub

Public Sub MyFirstTest()

   Const Expected As Long = vbMonday
   Dim Actual As Long
   
   Actual = Weekday(#1/1/2024#, vbSunday)
   
   Assert.That Actual, Iz.EqualTo(Expected)
   
End Sub