c++unit-testingqtvalgrindcxxtest

Testing a qt object using cxxtest framework and valgrind


Is it possible to use cxxunit or any other unit testing framework (excluding QtTestLib) to test qt widgets?

If yes, then there are two more questions :

  1. How?
  2. Since I am running unit tests using valgrind, can this report some errors?

Solution

  • Yes, it should be possible. I'm not sure about cxxunit specifically, but it is theoretically possible.

    1. To properly test Qt objects, you will probably need to create/destroy a QApplication object in your global setup and teardown functions. Unless you are specifically testing QApplication functionality, you should only create one for the entire run of the test application. This will allow you to test portions of the widget's logic, but not easily the appearance or UI interactivity of the widget. Also, testing certain items may rely on having the application's event loop running, which would be more difficult.
    2. Valgrind may report some errors. It may also report errors with Qt's code, in particular static allocations that are left to application teardown to reclaim.