TDD in Qt, how to use?
-
What is the correct way to use TDD in Qt? Create tests in the project itself or a separate project for each test?
-
You can take a look at the Qt Testing Framework. You could also use other C++ testing libraries, and they can work out just fine, too.
Here's some discussion on unit testing in Qt: "http://stackoverflow.com/q/1524390/1583123":http://stackoverflow.com/q/1524390/1583123
If you decide to use the Qt Testing Framework, take a look at the overview here: "http://qt-project.org/doc/qt-5/qtest-overview.html":http://qt-project.org/doc/qt-5/qtest-overview.html
And there's a good example on writing a unit test here: "http://qt-project.org/doc/qt-5/qttestlib-tutorial1-example.html":http://qt-project.org/doc/qt-5/qttestlib-tutorial1-example.html
A common paradigm is to create a separate project for tests. Here's some discussion on including the classes in your main project in your test project: "http://stackoverflow.com/q/11804038/1583123":http://stackoverflow.com/q/11804038/1583123. One answer there suggests using a .pri file and including in in your main project and test project. Alternatively, you can use * in your test project file to include all header and source files from your main project.
You can create a single test project for all your tests, or multiple projects to group your tests.
Here is how you can create multiple tests in the same project:
Read "this article":http://stackoverflow.com/q/1524390/1583123 (linked earlier) about alternatives to Qt Testing Framework. There are multiple posts there that include useful information on creating multiple test classes in the same project.
Also, there are some useful test supplement classes for the Qt Testing Framework written by individuals. Here's a good supplement from the Qt Creator Blog: "http://qtcreator.blogspot.ca/2010/04/sample-multiple-unit-test-project.html":http://qtcreator.blogspot.ca/2010/04/sample-multiple-unit-test-project.html