Set BinTest = New clsManagerBinFields
'如果目标文件存在,则删除这个文件
If Dir(DesFile) <> "" Then Kill DesFile
'建立一个新的Recordset,这里用一个虚拟的数据源来代替,这样就不用打开数据库了
k.Source = "test"
k.Fields.Append "thefile", adBinary, -1, adFldUpdatable
k.Open , , adOpenKeyset, adLockBatchOptimistic
k.AddNew
End Sub
'Destroy the test fixture
Public Sub ITestContainer_TearDown()
' TODO: destruct your test fixture here
' k.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\xpconnect\db\test.mdb;Persist Security Info=False"
' k.UpdateBatch adAffectAllChapters
' k.Close
'测试完成后自动完成
Set k = Nothing
Set BinTest = Nothing
End Sub
'Public Sub testSampleMethod(oTestResult As TestResult)
' TODO: add your test code here
'End Sub
Private Sub TestFieldtoFile(oTestResult As TestResult)
oTestResult.Assert BinTest.FieldToFile(DesFile, k!thefile), "导出到文件不成功"
End Sub
Private Sub TestFiletofield(oTestResult As TestResult)
oTestResult.Assert BinTest.fileTofield(SourceFile, k!thefile), "导入到数据库不成功"
End Sub
Public Sub TestFields(oTestResult As TestResult)
TestFiletofield oTestResult
TestFieldtoFile oTestResult
oTestResult.Assert FileLen(SourceFile) = FileLen(DesFile), "文件不相符!"
End Sub
写单元测试代码很简单,只要完成几个函数就可以了。
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
文章来源于领测软件测试网 https://www.ltesting.net/