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.
Posted by: Fiach Reid | 2006.03.25 at 06:23 AM
Posted by: Todd Girvin | 2006.03.25 at 09:24 AM
Posted by: alex | 2007.12.12 at 05:27 PM
Posted by: jimbo | 2009.09.14 at 02:56 AM
Posted by: Todd Girvin | 2009.09.14 at 07:01 AM