使用,把包下載,然后解到一個目錄,運行install.exe,打開VB?梢园l現可以新建CoMunit Test Project的工程。有兩個文件frmTestRunner的form,TCTestContainer是測試類。下面我們看一下如何使用comunit。先下載測試代碼。
這個代碼是測試二進制文件在數據庫里的存取。有關二進制代碼在數據庫里存取的技術問題,請看另一篇文章。用什么辦法來確定代碼是正確工作了呢?答案當然是單元測試。
測試代碼很簡單,但的確很有效,它保證這段代碼是正確的工作了。
' COMUnit 1.1 - TestContainer ClassOption Explicit
' Interface declaration
Implements ITestContainer
'定義一個recordset
Dim k As New adodb.Recordset
'定義bin類
Dim BinTest As clsManagerBinFields
'定義源文件名和目標文件名
Dim SourceFile As String, DesFile As String
' 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
ITestContainer_TestCaseNames = Array("TestFields")
End Property
' Run the specified test case methods in this test container
Public Sub ITestContainer_RunTestCase(oTestCase As ITestCase, oTestResult As TestResult)
On Error GoTo ErrorHandler
InvokeHook Me, oTestCase.Name, INVOKE_FUNC, oTestResult
' CallByName Me, oTestCase.Name, VbMethod, oTestResult
Exit Sub
ErrorHandler:
oTestResult.AddError Err.Number, Err.Source, Err.Description
End Sub
'Initialize the test fixture
'在測試開始時自動調用
Public Sub ITestContainer_Setup()
' TODO: initialize your test fixture here
'指定源文件名,這里就指定這個文件
SourceFile = App.Path & "\tctestcontainer.cls"
'指定目標文件名,這里指定為當前目錄下的test
DesFile = App.Path & "\test"
文章來源于領測軟件測試網 http://www.kjueaiud.com/