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

<p>Any links or tutorials would be appreciated.</p>

[{'answer_id': 3162, 'author': 'graham.reeds', 'author_id': 342, 'author_profile': 'https://Stackoverflow.com/users/342', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="https://github.com/unittest-cpp" rel="nofollow noreferrer">UnitTest++</a>.</p>\n\n<p>In the years since I made this post the source has moved from SourceForge to github.  Also the <a href="https://github.com/unittest-cpp/unittest-cpp/wiki/Writing-More-Tests-With-the-Bowling-Game-Kata" rel="nofollow noreferrer">example tutorial</a> is now more agnostic - doesn\'t go into any configuration or project set up at all.</p>\n\n<p>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 <a href="https://github.com/unittest-cpp/unittest-cpp/tree/sourceforge" rel="nofollow noreferrer">SourceForge</a> branch.</p>\n'}, {'answer_id': 8330, 'author': 'colgur', 'author_id': 1059, 'author_profile': 'https://Stackoverflow.com/users/1059', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve used <a href="http://cppunit.sourceforge.net/cppunit-wiki" rel="nofollow noreferrer">CppUnit</a> with VS2005 and Eclipse. The wiki is very thorough (especially if you are familiar with JUnit).</p>\n'}, {'answer_id': 8345, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m not 100% sure about VS2008, but I know that the Unit Testing framework that microsoft shipped in VS2005 as part of their Team Suite was only for .NET, not C++</p>\n\n<p>I\'ve used CppUnit also and it was alright. Much the same as NUnit/JUnit/so on.</p>\n\n<p>If you\'ve used boost, they <a href="http://www.boost.org/doc/libs/1_35_0/libs/test/doc/index.html" rel="nofollow noreferrer">also have a unit testing library</a></p>\n\n<p>The guys behind boost have some <strong>serious</strong> coding chops, so I\'d say their framework should be pretty good, but it might not be the most user friendly :-)</p>\n'}, {'answer_id': 11091, 'author': 'Ben Straub', 'author_id': 1319, 'author_profile': 'https://Stackoverflow.com/users/1319', 'pm_score': 2, 'selected': False, 'text': '<p>The framework included with VS9 <em>is</em> .NET, but you can write tests in C++/CLI, so as long as you\'re comfortable learning some .NET isms, you should be able to test most any C++ code.</p>\n\n<p><a href="http://www.boost.org/doc/libs/1_35_0/libs/test/doc/" rel="nofollow noreferrer">boost.test</a>\n and <a href="http://code.google.com/p/googletest/" rel="nofollow noreferrer">googletest</a>\nlook to be fairly similar, but adapted for slightly different uses. Both of these have a binary component, so you\'ll need an extra project in your solution to compile and run the tests.</p>\n\n<p>The framework we use is <a href="http://cxxtest.sourceforge.net/" rel="nofollow noreferrer">CxxTest</a>, which is much lighter; it\'s headers only, and uses a Perl (!) script to scrape test suite information from your headers (suites inherit from CxxTest::Base, all your test methods\' names start with "test"). Obviously, this requires that you get Perl from <a href="http://www.activestate.com/Products/activeperl/index.mhtml" rel="nofollow noreferrer">one source</a> or <a href="http://www.cygwin.com/" rel="nofollow noreferrer">another</a>, which adds overhead to your build environment setup.</p>\n'}, {'answer_id': 16548, 'author': 'Lehane', 'author_id': 142, 'author_profile': 'https://Stackoverflow.com/users/142', 'pm_score': 1, 'selected': False, 'text': '<p>The unit tester for Visual&nbsp;Studio&nbsp;2008 is only for .NET code as far as I know.</p>\n\n<p>I used CppUnit on Visual&nbsp;Studio&nbsp;2005 and found it to be pretty good. </p>\n\n<p>As far as I remember, the setup was relatively painless. Just make sure that in your testing projects the linker (Linker → Input → Additional Dependencies) includes cppunitd.lib. </p>\n\n<p>Then, <code>#include &lt;cppunit/extensions/HelperMacros.h&gt;</code> in your header.</p>\n\n<p>You can then follow the steps in <a href="http://cppunit.sourceforge.net/doc/1.11.6/cppunit_cookbook.html" rel="nofollow noreferrer">http://cppunit.sourceforge.net/doc/1.11.6/cppunit_cookbook.html</a> to get your test class working.</p>\n'}, {'answer_id': 30776, 'author': 'ZebZiggle', 'author_id': 2587612, 'author_profile': 'https://Stackoverflow.com/users/2587612', 'pm_score': 1, 'selected': False, 'text': "<p>I like the CxxTest as well for the same reasons. It's a header file only so no linking required. You aren't stuck with Perl as there is a Python runner as well. I will be reviewing the google library soon. The Boost stuff pulls in too much other baggage. </p>\n"}, {'answer_id': 35963, 'author': 'Aardvark', 'author_id': 3655, 'author_profile': 'https://Stackoverflow.com/users/3655', 'pm_score': 7, 'selected': True, 'text': '<p><a href="http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle" rel="nofollow noreferrer">This page</a> may help, it reviews quite a few C++ unit test frameworks:</p>\n\n<ul>\n<li>CppUnit  </li>\n<li>Boost.Test</li>\n<li>CppUnitLite </li>\n<li>NanoCppUnit</li>\n<li>Unit++</li>\n<li>CxxTest</li>\n</ul>\n\n<p>Check out <strong><em><a href="http://www.objectmentor.com/resources/downloads.html" rel="nofollow noreferrer">CPPUnitLite</a></em></strong> or <strong><em><a href="http://gamesfromwithin.com/?p=48" rel="nofollow noreferrer">CPPUnitLite2</a></em></strong>. </p>\n\n<p><em>CPPUnitLite</em> 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). </p>\n\n<p>CPPUnitLite attempts to make a true C++-style testing framework, not a Java one ported to C++. (I\'m paraphrasing from Feather\'s <a href="https://rads.stackoverflow.com/amzn/click/com/0131177052" rel="nofollow noreferrer" rel="nofollow noreferrer">Working Effectively with Legacy Code</a> book). <em>CPPUnitLite2</em> seems to be another rewrite, with more features and bug fixes.</p>\n\n<p>I also just stumbled across <strong><em><a href="http://sourceforge.net/projects/unittest-cpp/" rel="nofollow noreferrer">UnitTest++</a></em></strong> which includes stuff from CPPUnitLite2 and some other framework.</p>\n\n<p>Microsoft has released <strong><em><a href="http://winunit.codeplex.com/" rel="nofollow noreferrer">WinUnit</a></em></strong>. </p>\n\n<p>Also checkout <strong><em><a href="https://github.com/philsquared/Catch" rel="nofollow noreferrer">Catch</a></em></strong> or <strong><em><a href="https://github.com/onqtam/doctest" rel="nofollow noreferrer">Doctest</a></em></strong></p>\n'}, {'answer_id': 64482, 'author': 'moswald', 'author_id': 8368, 'author_profile': 'https://Stackoverflow.com/users/8368', 'pm_score': 3, 'selected': False, 'text': '<p>Personally, I prefer <a href="http://msdn.microsoft.com/en-us/magazine/cc136757.aspx" rel="noreferrer">WinUnit</a> since it doesn\'t require me to <a href="http://www.wintellect.com/cs/blogs/jrobbins/archive/2008/01/17/winunit-an-outstanding-native-c-unit-testing-tool.aspx" rel="noreferrer">write anything except for my tests</a> (I build a .dll as the test, not an exe).  I just build a project, and point WinUnit.exe to my test output directory and it runs everything it finds.  You can <a href="http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/MSDNMag2008_02.exe" rel="noreferrer">download the WinUnit project here</a>. (MSDN now requires you to download the entire issue, not the article.  WinUnit is included within.)</p>\n'}, {'answer_id': 824956, 'author': 'Jared', 'author_id': 24841, 'author_profile': 'https://Stackoverflow.com/users/24841', 'pm_score': 5, 'selected': False, 'text': '<p><strong>There is a way to test unmanaged C++ using the built in testing framework within Visual Studio 2008</strong>. 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++.</p>\n\n<p>I have step by step details on my blog here: <a href="http://msujaws.wordpress.com/2009/05/06/unit-testing-mfc-with-mstest/" rel="noreferrer">http://msujaws.wordpress.com/2009/05/06/unit-testing-mfc-with-mstest/</a></p>\n'}, {'answer_id': 1036682, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>The tools that have been mentioned here are all command-line tools. If you look for a more integrated solution, have a look at <a href="http://www.cfix-studio.com/" rel="nofollow noreferrer">cfix studio</a>, which is a Visual Studio AddIn for C/C++ unit testing. It is quite similar to TestDriven.Net, but for (unmanaged) C/C++ rather than .NET.</p>\n'}, {'answer_id': 1829212, 'author': 'aracntido', 'author_id': 191417, 'author_profile': 'https://Stackoverflow.com/users/191417', 'pm_score': 3, 'selected': False, 'text': '<p>Here is the approach I use to test the IIS URL Rewrite module at Microsoft (it is command-line based, but should work for VS too):</p>\n\n<ol>\n<li>Make sure your header files are consumable by moving source code to cpp files and using forward declaration if needed.</li>\n<li>Compile your code to test as library (.lib)</li>\n<li>Create your UnitTest project as C++ with CLR support.</li>\n<li>Include your header files.</li>\n<li>Include your .lib files.</li>\n<li>Add a reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</li>\n<li>Use a really small class for declaring your unit test and jump from managed to C++/Native code like this (may have typos):</li>\n</ol>\n\n<p>Here is an example:</p>\n\n<pre><code>// Example\n#include "stdafx.h"\n#include "mstest.h"\n\n// Following code is native code.\n#pragma unmanaged\nvoid AddTwoNumbersTest() {\n  // Arrange\n  Adder yourNativeObject;\n  int expected = 3;\n  int actual;\n  // Act\n  actual = yourNativeObject.Add(1, 2);\n  // Assert\n  Assert::AreEqual(expected, actual, L"1 + 2 != 3");\n}\n\n// Following code is C++/CLI (Managed)\n#pragma managed\nusing namespace Microsoft::VisualStudio::TestTools::UnitTesting;\n[TestClass]\npublic ref class TestShim {\npublic:\n  [TestMethod]\n  void AddTwoNumbersTest() {\n     // Just jump to C++ native code (above)\n     ::AddTwoNumbersTest();\n  }\n};\n</code></pre>\n\n<p>With this approach, people don\'t have to learn too much C++/CLI stuff, all the real test will be done in C++ native and the TestShim class will be used to \'publish\' the test to MSTest.exe (or make it visible).</p>\n\n<p>For adding new tests you just declare a new [TestMethod] void NewTest(){::NewTest();} method and a new void NewTest() native function. No macros, no tricks, straighforward.</p>\n\n<p>Now, the  heade file is optionally, but it can be used to expose the Assert class\' methods with C++ native signatures (e.g. wchar_t* instead of Stirng^), so it can you can keep it close to C++ and far from C++/CLI:</p>\n\n<p>Here is an example:</p>\n\n<pre><code>// Example\n#pragma once\n#pragma managed(push, on)\nusing namespace System;\nclass Assert {\npublic:\n    static void AreEqual(int expected, int actual) {\n        Microsoft::VisualStudio::TestTools::UnitTesting::Assert::AreEqual(expected, actual);\n    }\n\n    static void AreEqual(int expected, int actual, PCWSTR pszMessage) {\n        Microsoft::VisualStudio::TestTools::UnitTesting::Assert::AreEqual(expected, actual, gcnew String(pszMe\nssage));\n    }\n\n    template&lt;typename T&gt;\n    static void AreEqual(T expected, T actual) {\n        Microsoft::VisualStudio::TestTools::UnitTesting::Assert::AreEqual(expected, actual);\n    }\n\n    // Etcetera, other overloads...\n}\n#pragma managed(pop)\n</code></pre>\n\n<p>HTH</p>\n'}, {'answer_id': 13759497, 'author': 'Nayana Adassuriya', 'author_id': 1268258, 'author_profile': 'https://Stackoverflow.com/users/1268258', 'pm_score': 1, 'selected': False, 'text': '<p>I was suffering to implement unit testing for an unmanaged C++ application in a Windows environment with Visual Studio. So I managed to overcome and wrote a post as a step-by-step guidance to unmanaged C++ application unit testing. I hope it may help you.</p>\n\n<p><em><a href="http://codeketchup.blogspot.sg/2012/12/unit-test-for-unmanaged-c-in-visual.html" rel="nofollow noreferrer">Unit test for unmanaged C++ in Visual Studio </a></em></p>\n'}]
['https://Stackoverflow.com/questions/3150', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/370/']