|
Boost Users : |
Subject: Re: [Boost-users] Unit Test for vc++ exe project possible?
From: Richard (legalize+jeeves_at_[hidden])
Date: 2013-04-15 00:54:58
[Please do not mail me a copy of your followup]
boost-users_at_[hidden] spake the secret code
<1365867152886-4645293.post_at_[hidden]> thusly:
>I see a good tutorial for Boost Test using Visual Studio.
>(http://legalizeadulthood.wordpress.com/2009/07/04/c-unit-tests-with-boost-test-part-1/)
Thanks.
>But it looks like only forstatic or dynamic library.
>
>Is that possible to unit test the exe production project using Boost Test?
This isn't really possible due to the way that the C/C++ link
mechanism works.
What you need to do is to refactor your executable into a simple
delegating stub for main() and a static library for all the other
code.
Then you can unit test everything in the static library (including
your new main).
For instance, you start with:
main.cpp:
int main(int argc, char *argv[])
{
// some code you want to test
return 0;
}
Rename this function to exe_main:
exe_main.cpp:
int exe_main(int argc, char *argv[])
{
// some code you want to test
return 0;
}
and create a delegating stub:
main.cpp:
extern int exe_main(int argc, char* argv[]);
int main(int argc, char* argv[])
{
return exe_main(argc, argv);
}
Then move exe_main.cpp and all the other cpp files into a static
library. Then you can unit test everything.
-- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net