Building and running C++ unit tests in Visual Studio (TDD)

I have a large project for which I am attempting to use TDD. I am using Tut as my test framework, which has its flaws but is sufficient for what I need.

I need to exploit link time test seams, each test must be in its own executable . The project for this executable then launches itself as a post build step.

Unfortunately, this means that my Visual Studio Sln is filling up with tests, which is not scalable and also hides the actual important projects.

Does anyone know of a better way of running these tests? Is it possible to hide projects from a build and yet still have them build?


"Is it possible to hide projects from a build and yet still have them build?"

You can make separate solution for test cases. Then you can set up post build step of your main projects. This post-build should build tests-projects via separate solution and run them. Building test-projects should be done via command line (see eg here for details).

If you need to link your unit tests with some lib-s from main projects, you can use

#pragma comment(lib, "libname")

See this MSDN page for details.


You could try to group your tests into folders (are they called filters?) within your solution in Solution Explorer. This would separate tests from your other projects.

But, otherwise, could you avoid using link time test seams (Yes, I know, its probably too late to suggest this) and use polymorphism to provide your run-time variation and have less test projects?


Don't know if you're still looking for a solution. But here's an idea:

You can keep all your tests in one library and write an application that spawns itself and executes each test. This way you end up with one executable (and hence one project) for a suite and each test will be like a separate executable.

This is in-fact the mechanism used in CUnitWin32. You might even be able to wrap your tests in that framework.

链接地址: http://www.djcxy.com/p/41926.html

上一篇: 哪一个是最适合Java的JSON重写器?

下一篇: 在Visual Studio(TDD)中构建和运行C ++单元测试