Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to test the code from application (as opposed to library)?
I'm trying to figure out how to do automated testing with the help of Qt Test . Since a test itself is an application (.exe on Windows), testing libraries is no problem - add proper INCLUDEPATH and LIBS to the project just as if linking any other application with this library. But how do I test the code that resides in the app-type project? You can't link an application to another application.
Do I have to directly include the source files being tested into the test project? This can be non-trivial - there may be many dependencies, including 3rd-party libraries.
@Violet-Giraffe What tests do you want to write? Unit tests? Feature tests? System tests?
Feature tests, I suppose. Or unit tests. There doesn't seem to be much difference in this context. Even when I'm unit-testing a single class or even single method, it still may require a lot of dependencies that I'm not keen on duplicating in the test.pro file (but I don't see any other way).
@Violet-Giraffe For such tests you do not need your executable. Instead you create test executables where you include parts of your source code which you want to test. Take a look at http://doc.qt.io/qt-5/qtest-tutorial.html
Even when I'm unit-testing a single class or even single method, it still may require a lot of dependencies
You can mock the dependencies.
Violet Giraffe last edited by Violet Giraffe
Instead you create test executables where you include parts of your source code which you want to test.
I know. And I've seen the tutorial but it fails to address any real-life problems, the example is too artificially simple.
So you suggest including the .cpp and .h files being tested - however many of them - directly into the test.pro?
An interesting idea about mocking, thanks.
@Violet-Giraffe Yes, you add the source files which you want to test and mock as many dependencies as possible.
It is a good idea to do TDD - Test Driven Development. First write the tests which fails, then implement the actual functionality until the tests pass. This way you write code which can be tested more easily. Writing first the code and then the tests can be challanging.