Unit Testing in C++
Back in the C++ world you really feel how good tool support makes you much more productive.
I learned to love TDD (Test Driven Development) so I wanted to continue using it in my C++ projects. So I have tried a lot of the available unit testing tools a good overview is available at Games from Within Exploring the C++ Unit Testing Framework Jungle.
But those Frameworks doesn’t feel right. Either you had to derive from a base class and/or you had manually to register the tests.
But as a long time .Net developer I’m used to add two Attributes and the test is ready to run in NUnit or MsTest.
After some time a finally found a UnitTesting framework that is like I wanted the framework to be.
It’ called WinUnit. It offered exactly what I was looking for.
- no need to derive from a class
- no need to manually register the test
- no extra functionality needed to run the tests
Just compile the test project to a .dll and call the framework with the location of the .dll as parameter. Simple and it works.
Also positive is the easy way I could implement it directly into Visual Studio. How to do it is described in the WinUnit article. I use the external tool possibility because I don’t want to run the test after each build, because with a lot of tests this can take some time.
But to further improve thee process I’ve written a small macro that firstly invokes the build process so that the test project is always up to date when the test run. After the build is finished it will call WinUnit and all tests will run.
When the macro is invoked it will always build and run the actual selected project.
The Code:
Public Module BuildAndRunWinUnitTest
Sub BuildAndRunWinUnitTest()
DTE.Solution.SolutionBuild.Build(True)
DTE.ExecuteCommand("Tools.ExternalCommand6")
DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
End Sub
End Module
