« Service Orientation, Law of Demeter | Main | Clemens on Transactional Queues »

2004.12.10

Testing VB6 with NUnit

We at Improving are huge fans of test-driven development (TDD).  I just started a short project for a client who requires the development (for very valid reasons) to be done in VB6.  I did a little research around TDD in VB6 and found vbUnit as well as some other tools.  However, months ago I'd heard about the rare and mysterious practice of unit testing VB6 code from NUnit.  Only, I couldn't find a single reference to it with Google.  So, here's what I learned from one of my wife's coworkers....

1. Create your VB6 code in an ActiveX DLL project (e.g. Project).  Add and develop classes as normal in this project.

2. Use menu item File|Make DLL to copile the DLL (e.g. Project.dll) and automatically register it for use.

3. In Microsoft Visual Studio .Net (or 2003), create a DLL solution and add references to the .Net assembly NUnit.Framework and the COM library produced by VB6 (e.g. Project).  VS.Net auto-gens a COM wrapper for you (e.g. Interop.Project.dll) in the bin directory.

4. Write .Net test cases to invoke member functions of classes in Project. You can make a using Project; statement if desired.  Build your DLL as normal.

5. Execute tests by FIRST running the ActiveX DLL from the VB6 environment.  This puts VB6 in debug mode.  Set a breakpoint somewhere to prove that it's working.  SECOND: launch NUnit, open your .Net assembly, and run some tests. 

NOTE: If you don't run the VB DLL first, NUnit will report a System.Runtime.InteropServices.COMException

Of course, once you're up and running, you'll want to change the order of these steps so you're actually writing your tests first. ;)

I hope to have NO other words of wisdom about hard to find answers to VB6 development questions from this project.  But, it is worth mentioning that www.connectionstrings.com had the answer I needed for connecting to a password-protected database with ADO.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451806669e200d83456faaa69e2

Listed below are links to weblogs that reference Testing VB6 with NUnit:

Comments

Any ideas on how to apply this technique to VB6 .EXE's rather than DLL's?
No, man. Sorry I can't help you there. I'm not doing VB6 dev anymore so I don't even have an environment to experiment. Testing is one motivation for separating out "application services", or services provided by an application into a DLL and making your EXE just the presentation layer with your forms and such. Of course, the other reason is just good layering practice to separate concerns between presentation, app service, domain logic, and persistence.
Just use simplyvbunit to use VB6 unit testing (exes as well as dlls) and avoid paying fees for software. http://simplyvbunit.sourceforge.net/

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

November 2008

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Blog powered by TypePad

We Like