Neutrino
Neutrino

Reputation: 9586

How can I add a unit test to a C++ console program in Visual Studio 2012?

How can I add a unit test to a C++ console program in Visual Studio 2012?

From what I've been able to gather from the MSDN the MS unit test support for C++ can't do this at all, (which doesn't surprise me as the MS C++ unit test support was always shocking).

However in earlier versions of Visual Studio you used to be able to unit test C++ code using Visual Assist, but sadly this doesn't support vs2012.

Does anyone know of a C++ unit test framework with some sort of IDE integration that works with vs2012?

Upvotes: 1

Views: 1558

Answers (2)

Steve
Steve

Reputation: 7271

Visual studio does support integrated unit testing. You need to structure your program correctly though. The way I like to structure my solutions is to have three projects.

  • A .lib project that has my source code in it.
  • An executable project, linked with the .lib. This calls into the .lib in the main() call
  • A test project (exe), linked with the .lib.

Whilst it is possible to use the Visual Studio testing framework, I would recommend Google test. One of the best things about google test is actually Google mock. You can get some integration with this plugin.

Upvotes: 4

Ray Tayek
Ray Tayek

Reputation: 10003

You can write your tests in C++/CLI and use NUnit

Upvotes: 0

Related Questions