Unit testing with QTestLib
I'm trying to unit-testing my Qt application with QTestLib. I saw that the new Visual Studio 2012 has a built-in C++ test framework and googling for it I saw this page that talks about different methods to test a native project. I would have two different projects, one for the normal program and one for the tests. Actually my application is not a DLL but it's a simple C++ exe. Is the best way to test it with another project to link against .obj files or against libs? I wouldn't export anything from the source code as mine is not a DLL
This is a typical QtTest project with three code units: unit1, unit2 and unit3
project/ ├── project.pro ├── src │ ├── main.cpp │ ├── src.pro │ ├── unit1.cpp │ ├── unit1.h │ ├── unit2.cpp │ ├── unit2.h │ ├── unit3.cpp │ └── unit3.h └── tests ├── stubs │ ├── stubs.pro │ ├── unit1_stub.cpp │ ├── unit2_stub.cpp │ └── unit3_stub.cpp ├── test1 │ ├── test1.cpp │ ├── test1.h │ └── test1.pro ├── test2 │ ├── test2.cpp │ ├── test2.h │ └── test2.pro ├── test3 │ ├── test3.cpp │ ├── test3.h │ └── test3.pro └── tests.pro
This project results in 4 binaries: 1 application itself and three test binaries for testing each of the units. For example, test1 should include src/unit1.cpp, src/unit1.h and also stubbed unit2 and unit3: src/unit2.h, tests/stubs/unit2_stub.cpp, src/unit2.h, tests/stubs/unit3_stub.cpp. With this kind of setup src/unit1.cpp and tests/stubs/unit1_tests.cpp will be compiled twice and this number will grow, if number of units will be larger. This is not a problem for small projects, but for huge projects this may lead to significant increase of build time.
Then splitting unitX.cpp and unitX.h into separate libraries with static linking to main application and each of the tests will eliminate need for building multiple times.