mardi 5 juillet 2016

Running QtQuickTest unit tests

The QtQuickTest docs don't make it clear how to refer to other components, run tests on them, etc.

It is relatively simple to write a tst_foo.qml, define a GUI object and a TestCase inside it that runs functions called test_* that checks aspects of your GUI object, but that is not a real-world situation. You would have your components to test in files that are not called tst_*. So my questions are:

  • The tester automatically runs all QML files called tst_*.qml. This implies that there are separate qml file with unit tests. But so far, I have only been able to do what this person does: rename the QML object you want to test to tst_foo.qml and define a TestCase in it. So the subsequent questions are:
  • Are you supposed to define a TestCase inside the GUI element and call it from a tst_foo.qml file? If so, how?
  • Or are you supposed to define a TestCase inside tst_foo.qml that refers to your GUI component? If so, how?

Another issue is that the QML loader for the unit test seems to use QQuickView, so it can only load items derived from QQuickItem. So how do you test an ApplicationWindow? In this case, renaming your QML file to tst_mainApp.qml doesn't even work: "QQuickView only supports loading of root objects that derive from QQuickItem."

Aucun commentaire:

Enregistrer un commentaire