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


Question

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.

1
92
10/14/2009 11:53:36 PM

Accepted Answer

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.

Also checkout Catch or Doctest

56
10/17/2016 6:24:53 PM

There is a way to test unmanaged C++ using the built in testing framework within Visual Studio 2008. If you create a C++ Test Project, using C++/CLI, you can then make calls to an unmanaged DLL. You will have to switch the Common Language Runtime support to /clr from /clr:safe if you want to test code that was written in unmanaged C++.

I have step by step details on my blog here: http://msujaws.wordpress.com/2009/05/06/unit-testing-mfc-with-mstest/


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon