Do I have to create a static library to test my application?

Posted by Christopher Gateley on Stack Overflow See other posts from Stack Overflow or by Christopher Gateley
Published on 2010-04-21T07:00:38Z Indexed on 2010/04/21 7:03 UTC
Read the original article Hit count: 262

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 either 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?

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about TDD