开发者

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?


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.


If you want to test your UI, I suggest to use a UI testing tool like Squish. Unit tests I find more suited to test the logic behind the widgets, not the widgets itself. If you really want to unit-test your Qt widgets, I don't think there is a better solution than QtTestLib.

Valgrind: There is a valgrind plugin for Squish. I haven't used that one myself though. Other unit tests can of course easily be run in valgrind, although I don't know of any solution that fully automates this. One would have to make sure to really suppress all warnings from outside one owns code so that some error in e.g. x11 libs doesn't trigger the unit test to fail.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜