hmLoadTopic({ hmKeywords:"Unit testing (VBUnit),VBUnit,VBUnit using with Coverage Validator", hmTitle:"Working With VBUnit", hmDescription:"This page gives information about using Coverage Validator with programs that use VBUnit. ", hmPrevLink:"example-isapi-source-code.html", hmNextLink:"working-with-visual-basic-6-vb.html", hmParentLink:"index.html", hmBreadCrumbs:"", hmTitlePath:"Working With VBUnit", hmHeader:"
<\/p>\n\r
This page gives information about using Coverage Validator with programs that use VBUnit. <\/p>\n\r
<\/p>\n\r
<\/p>\n\r
VBUnit works by spawning a worker service process, vbUnitTestServer.exe<\/span> which works in conjunction with the main process RunVBUnit.exe<\/span>.<\/p>\n\r <\/p>\n\r Because vbUnitTestServer.exe<\/span> is a service and is not launched directly using CreateProcess<\/span> from RunVBUnit.exe<\/span> we can\'t monitor and hook this process. <\/p>\n\r <\/p>\n\r This means that to get the Coverage Validator stub dll into your Visual Basic process you\'ll have to load the stub dll yourself. <\/p>\n\r <\/p>\n\r At the time of writing, the current VBUnit is VBUnit3.<\/p>\n\r <\/p>\n\r <\/p>\n\r There are two steps: preparing the executable and running the test.<\/p>\n\r <\/p>\n\r <\/p>\n\r <\/p>\n\r To load the Coverage Validator stub dll into your Visual Basic process do the following steps:<\/p>\n\r <\/p>\n\r 1)<\/span> Copy svlCoverageValidatorStub.dll<\/span> to the same directory (or any directory on the \$<\/span>PATH<\/span>) as the Visual Basic executable (or DLL) you wish to test.<\/p>\n\r <\/p>\n\r 2)<\/span> Copy DbgHelp.dll<\/span> from the Coverage Validator install directory to the same directory (or any directory on the <\/span>\$<\/span>PATH<\/span>) as the Visual Basic executable (or DLL) you wish to test. <\/p>\n\r <\/p>\n\r Don\'t copy the DbgHelp.dll<\/span> <\/span>from elsewhere as you may get an earlier version of the DbgHelp.dll<\/span> and not be able to read symbols as a result.<\/p>\n\r <\/p>\n\r 3)<\/span> Modify the start of your test DLL or exe so that the first thing it does is load the Coverage Validator stub DLL.<\/p>\n\r <\/p>\n\r Do this as follows:<\/p>\n\r <\/p>\n\r a) Add these lines to the start<\/span> of your Visual Basic code.<\/p>\n\r <\/span> b) Add these lines where you wish to load<\/span> the Coverage Validator DLL.<\/p>\n\r <\/p>\n\r <\/span>Dim<\/span> <\/span>lbCVStub<\/span> <\/span>As<\/span> <\/span>Long<\/span> <\/span> c) Add this line where you wish to unload <\/span>the Coverage Validator DLL. <\/p>\n\r <\/p>\n\r <\/span>FreeLibrary<\/span> <\/span>lbCVStub<\/span><\/p>\n\r <\/span><\/p>\n\r This step is optional, but do it as close to the end of the execution of your DLL or EXE as possible.<\/p>\n\r <\/p>\n\r 4)<\/span> Ensure each VB exe or DLL has been built with debug symbols. Debug symbols are required so that Coverage Validator can monitor each line visit.<\/p>\n\r <\/p>\n\r Do this as follows:<\/p>\n\r <\/p>\n\r a) Open the Visual Studio properties dialog for the project. Project<\/span> Menu Properties...<\/span><\/p>\n\r <\/p>\n\r b) Go to the Compile<\/span> tab.<\/p>\n\r <\/p>\n\r c) Select the Compile to Native Code<\/span> radio box.<\/p>\n\r <\/p>\n\r d) Check the Create Symbol Debug Info<\/span> check box. Click OK<\/span>.<\/p>\n\r <\/p>\n\r e) Make the project. File<\/span> Menu Make<\/span> [name of project].<\/p>\n\r <\/p>\n\r <\/span><\/p>\n\r <\/p>\n\r <\/p>\n\r 1)<\/span> Setup where the Visual Basic PDB files are stored<\/p>\n\r <\/p>\n\r Do this as follows:<\/p>\n\r <\/p>\n\rUsing Coverage Validator with VBunit<\/span><\/h1>\n\r
<\/span><\/h1>\n\r
Step 1: Modifying the VB DLL\/EXE<\/span><\/h1>\n\r
\n\r <\/span>Private<\/span> <\/span>Declare<\/span> <\/span>Function<\/span> <\/span>FreeLibrary<\/span> <\/span>Lib<\/span> <\/span>"kernel32"<\/span> <\/span>(ByVal<\/span> <\/span>hLibModule<\/span> <\/span>As<\/span> <\/span>Long)<\/span> <\/span>As<\/span> <\/span>Long<\/span>
\n\r <\/span>Private<\/span> <\/span>Declare<\/span> <\/span>Function<\/span> <\/span>LoadLibrary<\/span> <\/span>Lib<\/span> <\/span>"kernel32"<\/span> <\/span>Alias<\/span> <\/span>"LoadLibraryA"<\/span> <\/span>(ByVal<\/span> <\/span>lpLibFileName<\/span> <\/span>As<\/span> <\/span>String)<\/span> <\/span>As<\/span> <\/span>Long<\/span><\/p>\n\r
\n\r <\/span><\/p>\n\r
\n\r <\/span>
\n\r <\/span>lbCVStub<\/span> <\/span>=<\/span> <\/span>LoadLibrary(<\/span>"svlCoverageValidatorStub"<\/span>)<\/span><\/p>\n\r
\n\r <\/span><\/p>\n\r <\/span><\/h1>\n\r
Step 2: Setting up Coverage Validator<\/span><\/h1>\n\r