How to set up unit testing for Visual Studio C++

By : DShook

I'm having trouble figuring out how to get the testing framework set up and usable in Visual Studio 2008 for C++ presumably with the built-in unit testing suite.

Any links or tutorials would be appreciated.

By : DShook


I use UnitTest++.

In the years since I made this post the source has moved from SourceForge to github. Also the example tutorial is now more agnostic - doesn't go into any configuration or project set up at all.

I doubt it will still work for Visual Studio 6 as the project files are now created via CMake. If you still need the older version support you can get the last available version under the SourceForge branch.

This page may help, it reviews quite a few C++ unit test frameworks:

  • CppUnit
  • Boost.Test
  • CppUnitLite
  • NanoCppUnit
  • Unit++
  • CxxTest

Check out CPPUnitLite or CPPUnitLite2.

CPPUnitLite was created by Michael Feathers, who originally ported Java's JUnit to C++ as CPPUnit (CPPUnit tries mimic the development model of JUnit - but C++ lacks Java's features [e.g. reflection] to make it easy to use).

CPPUnitLite attempts to make a true C++-style testing framework, not a Java one ported to C++. (I'm paraphrasing from Feather's Working Effectively with Legacy Code book). CPPUnitLite2 seems to be another rewrite, with more features and bug fixes.

I also just stumbled across UnitTest++ which includes stuff from CPPUnitLite2 and some other framework.

Microsoft has released WinUnit (via MSDN magazine). The download link for the code seems broken, but here is a link found in the comments here.

* Update: WinUnit Homepage *

By : Aardvark

I was suffering to implement unit test for unmanaged C++ application in windows environment with Visual Studio. So I manage to overcome and wrote a post as a step by step guidance to unmanaged C++ Application Unit Test. Hope It may help you.

This video can help you solving your question :)
By: admin