开发者

Unit Testing in QTestLib - running single test / tests in class / all tests

I'm just starting to use QTestL开发者_如何学Goib. I have gone through the manual and tutorial. Although I understand how to create tests, I'm just not getting how to make those tests convenient to run. My unit test background is NUnit and MSTest. In those environments, it was trivial (using a GUI, at least) to alternate between running a single test, or all tests in a single test class, or all tests in the entire project, just by clicking the right button.

All I'm seeing in QTestLib is either you use the QTEST_MAIN macro to run the tests in a single class, then compile and test each file separately; or use QTest::qExec() in main() to define which objects to test, and then manually change that and recompile when you want to add/remove test classes.

I'm sure I'm missing something. I'd like to be able to easily:

  • Run a single test method
  • Run the tests in an entire class
  • Run all tests

Any of those would call the appropriate setup / teardown functions.

EDIT: Bounty now available. There's got to be a better way, or a GUI test runner that handles it for you or something. If you are using QtTest in a test-driven environment, let me know what is working for you. (Scripts, test runners, etc.)


You can run only selected test cases (test methods) by passing test names as command line arguments :

myTests.exe myCaseOne myCaseTwo

It will run all inits/cleanups too. Unfortunately there is no support for wildcards/pattern matching, so to run all cases beginning with given string (I assume that's what you mean by "running the tests in an entire class"), you'd have to create script (windows batch/bash/perl/whatever) that calls:

myTests.exe -functions

parses the results and runs selected tests using first syntax.

To run all cases, just don't pass any parameter:

myTests.exe


The three features requested by the OP, are nowadays integrated in to the Qt Creator.

The project will be automatically scanned for tests and they apear on the Test pane. Bottom left in the screenshot:

Unit Testing in QTestLib - running single test / tests in class / all tests

Each test and corresponding data can be enabled by clicking the checkbox. The context menu allows to run all tests, all tests of a class, only the selected or only one test. As requested.

The test results will be available from the Qt Creator too. A color indicator will show pass/fail for each test, along additional information like debug messages.

In combination with the Qt Creator, the use of the QTEST_MAIN macro for each test case will work well, as each compiled executable is invoked by the Qt Creator automatically.

For a more detailed overview, refer to the Running Autotests section of the Qt Creator Manual.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜