| ' COMUnit 1.1 - TestContainer Class
Option 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"
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
|