UnitTest ++ and basic

I want to give TDD a try, and I chose the UnitTest ++ structure, but the documentation almost does not exist (as far as I know).

My concern is this: in all the tutorials I've seen, they put UnitTest::RunAllTests() in the main() function. I assume that they do this only to simplify the explanation, but I do not want this with my software. Where should I put UnitTest::RunAllTests() so that I can execute it every time I create software, but not when it starts?

+1
c ++ unit-testing
source share
2 answers

UnitTest::RunAllTests() should be placed in the main function of a separate program that you compile and execute as part of the build process.

+4
source share

One thing we have done in the past is to add a command line argument that forces the main executable to run all tests and then exit. It’s pretty easy to organize some #ifdefs so that this code compiles into release builds. Something like this (this is not very C ++, but if you did not understand the command line arguments, this is the easiest way to do this):

 int main (int argc, char *argv[]) { #ifdef DEBUG if (argc > 1 && !strcmp(argv[2], "-t")) { return UnitTest::RunAllTests(); } #endif [rest of program] } 
0
source share

All Articles