2

How to create/launch integration test in QT? For example, I want to test my application on receiving events and check signals with QSignalSpy, but it looks like there is no option to execute your application and test after that.

Update: I'm familiar with QTest and using it - I'm actually looking how to launch custom application, not base one with QTEST_MAIN macro

htzfun
  • 1,231
  • 10
  • 41

1 Answers1

1

have a look at QTest. It is designed for unit testing but you can use it to launch your application, perform mouse clicks and key presses on objects. It does present a bit of a headache whenever you get a modal window, but there are workarounds on SO.

mike
  • 1,192
  • 9
  • 32
  • I misslead you a little, I'm already using it - I managed to launch for custom QApplication and perform events using QTimer, but it doesn't feel right because there is no tutorials or documentation for such usage - there are only a lot examples how to improve and use unit testing - but no mocs, and you can only use macro QTEST_MAIN to launch app - but you can't to do this to your app. If you have any link with example of custom application class testing, I would really appreciate it. – htzfun Apr 18 '17 at 19:55
  • I don't use QTEST_MAIN at all. I use an approach similar to the test suite approach in this question: https://stackoverflow.com/questions/2750005/testing-with-qts-qtestlib-module/2760185#2760185. (the answer from foolo). I wrote a small application to handle arguments (to filter different suites, etc) and pass them into QTest::qExec. You just need to have a QApplication declared and it all works pretty well. – mike Apr 19 '17 at 10:01
  • just to be clear; you have a general QApplication declared (but not exec()'d) in the main function of a small executable that iterates over testSuite classes. Each of your set of tests is a subclass of testSuite, and you write QTest tests within those as per the normal QTest examples. To run your custom application in those test functions, you only need to instantiate your application. The event loop is started (I presume) by QTest::qExec, which takes your testSuite (a QObject) as an argument – mike Apr 19 '17 at 10:32
  • I successfully launched my application using QApplication a(argc, argv); a.exec(); But then how do I test mouse clicks and such? I want my test to click a specific button which changes an instance variable. And then I want to test if this variable was changed by the click. – The Coding Wombat May 21 '20 at 11:13
  • QTest::mouseclick lets you click on a widget – mike May 22 '20 at 20:10