views:

178

answers:

2

For various C++ library projects in VS2008 I have a sibling project called <libraryname>-Test. This is an executable project that depends on the library and runs tests on it. The post-build configuration of the test project consists of simply:

"$(TargetPath)"

Visual Studio won't re-run the post-build step unless it actually does something during the build, a re-link at the least. Normally that's a good thing, but in this case I want the tests to be re-run each time the solution build is triggered (as opposed to project builds which build only the dependent projects needed for the real program).

So far, the only way I've found to cause the tests to be run each time is to delete one of the intermediate files as part of the post-build process. This works, but slows things way down, as the test projects then need to be rebuilt even when nothing has changed.

+1  A: 

Put the test run into the post-build step of your main project, rather than the test project. Since it's getting rebuilt anyway, the test will always run.

Billy ONeal
I don't want to re-run the tests on *every* build of the program, I just want to be able to run them on-demand. Ideally by doing a solution build, because that's what the CI build machine does on a regular basis. That's why I specifically differentiated project builds from solution builds in the question.
Tim Sylvester
Then set the post build event on release builds of your project only. Use release builds for your final projects that are shipped/need to be tested. Then develop using the debug build.
Billy ONeal
A: 

are you using a CI server like CruiseControl or Hudson? You can usually script things like that in them. Or just use Nant even. They all support post build events.

ryber
No, the CI system is all home-grown batch files and ... stuff. The tests run fine on the CI machine anyway, it's on developer machines that the current system is causing complaints.
Tim Sylvester