samedi 29 août 2015

How to test signal-slot connections with qtest

I am just starting out with QT and would like to have unit tests. I found a blueprint for a project structure that supports having tests outside my application.

For my first test I wanted to have a click on the "Quit" menu point, checking that the close action of QMainWindow is really called.

Coming from Java with all its mocking frameworks, here is what I would like to do:

  1. Simulate Click on Menu (or key press)
  2. Click on Quit Action (or key press)
  3. Verify that signal "triggered()" of QAction was emitted
  4. Verify that slot "close" of QMainWindow was called

I read the qtest tutorial, KDE documentation and other stuff on the net but I am not able to express that using qtest (yet).

I found Qt UI testing: How to simulate a click on a QMenuBar item using QTest? which describes a similar thing, but even there only 1, 2, 3 are covered (And I was not even able to get them to work).

So how can I write such a test case? Is that even possible?

Aucun commentaire:

Enregistrer un commentaire