Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run your unit tests? Compiler flags? Static libraries?

I'm just getting started with TDD and am curious as to what approaches others take to run their tests. For reference, I am using the google testing framework, but I believe the question is applicable to most other testing frameworks and to languages other than C/C++.

My general approach so far has been to do one of three things:

  1. Write the majority of the application in a static library, then create two executables. One executable is the application itself, while the other is the test runner with all of the tests. Both link to the static library.

  2. Embed the testing code directly into the application itself, and enable or disable the testing code using compiler flags. This is probably the best approach I've used so far, but clutters up the code a bit.

  3. Embed the testing code directly into the application itself, and, given certain command-line switches either run the application itself or run the tests embedded in the application.

None of these solutions are particularly elegant...

How do you do it?

like image 392
kurige Avatar asked Apr 21 '10 07:04

kurige


People also ask

How do I run a CPP unit test in Visual Studio?

Right-click your solution and choose Add > New > Project. Click the Visual C++ category, and choose the Test sub-category. Select Native Unit Test Project, give the project a descriptive name, and then click OK.


1 Answers

Your approach no. 1 is the way I've always done it in C/C++ and Java. Most of the application code is in the static library and I try to keep the amount of extra code needed for the application to a minimum.

The way I approach TDD in Python and other dynamic languages is slightly different in that I leave the source code for the application and tests lying around and a test runner finds the tests and runs them.

like image 96
quamrana Avatar answered Oct 28 '22 03:10

quamrana