在使用过NUnit后,一直想在VB6中使用一下单元测试工具,目前比较流行的是VBUnit和ComUnit,我比较喜欢ComUnit主要是它是开源的,当然用起来比较爽了,可以在http://comunit.sourceforge.net/进行下载。
ComUnit使用比较简单,注意下边几点后就可以使用了。
' COMUnit 1.1 - TestRunner form Option Explicit ' Initialize the TestRunner control Private Sub Form_Load() ' TODO: add instances of your TestContainer classes to the UnitRunner control ' e.g. UnitRunner1.AddTestContainer New TCTestContainer '************************************************ '必须向UnitRunner添加一个控制对象,别的不需要修改 UnitRunner1.AddTestContainer New TCTestContainer '************************************************ End Sub ' Run the tests selected in the UnitRunner Private Sub btnRun_Click() UnitRunner1.Run End Sub ' Close the form Private Sub btnClose_Click() Unload Me End Sub ' Resize the UnitRunner control and the buttons on the form Private Sub Form_Resize() UnitRunner1.Move 0, 0, ScaleWidth, PosInt(ScaleHeight - btnClose.Height - 50) btnClose.Move PosInt(ScaleWidth - btnClose.Width), PosInt(ScaleHeight - btnClose.Height) btnRun.Move PosInt(ScaleWidth - btnClose.Width - btnRun.Width - 100), PosInt(ScaleHeight - btnRun.Height) End Sub Private Function PosInt(iValue) As Integer PosInt = IIf(iValue > 0, iValue, 0) End Function ' COMUnit 1.1 - TestContainer Class '建议类的前缀为TC Option Explicit ' Interface declaration Implements ITestContainer ' Fixture Member Variables ' TODO: specify your TestContainer test fixture member variables here ' Return the name of the different test case methods in this test container Public Property Get ITestContainer_TestCaseNames() As Variant() ' TODO: add the names of your test methods as a parameter into the Array() function |