Native code unit testing in VS

posted in Perpetual Alpha
Published August 08, 2009
Advertisement
Decided that since I was setting this up for my project anyway I'd grab a few screenshots and walk through the process of setting up testing of native code with Visual Studios testing framework.

The working name of the game is Project Baltar. So, the solution I created has that name, and I had no choice but to name the engine Gaius. No choice at all [smile]. The engine itself is a static library. And I inserted the following code to be tested:


So now that I have this native code that I want to test, I create a test project, which in the New Project dialog is under Visual C++ -> Test -> Test Project. I called it GaiusTest. The key thing to note is that you need to set the /clr flag, as opposed to /clr:safe to allow the native interop.


To the default test class that was created by the wizard, UnitTest1.cpp I added the include
#include "../Gaius/example.h"
and inserted the test code you see in the following shot. In order to make this compile I added Gaius as a dependency for GaiusTest by right clicking on GaiusTest in the Solution Browser pane and selecting Project Dependencies.


Finally to run the test, I selected Test->Windows->Test List Editor. There was only the one test on the list, so I ticked the box beside it, and hit the Run Checked Tests button at the top left of the test list editor window. And this is the final result:
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement