QTestLib 中的单元测试 - 运行单个测试/类中的测试/所有测试
我刚刚开始使用 QTestLib。我已阅读手册和教程。尽管我了解如何创建测试,但我只是不知道如何使这些测试方便运行。我的单元测试背景是NUnit 和MSTest。在这些环境中,只需单击右键,即可在运行单个测试、单个测试类中的所有测试或整个项目中的所有测试之间进行切换(至少使用 GUI)。
我在 QTestLib 中看到的只是使用 QTEST_MAIN 宏在单个类中运行测试,然后分别编译和测试每个文件;或者在 main()
中使用 QTest::qExec()
来定义要测试的对象,然后手动更改它并在需要添加/删除测试类时重新编译。
我确信我错过了一些东西。我希望能够轻松地:
- 运行单个测试方法
- 在整个类中运行测试
- 运行所有测试
其中任何一个都会调用适当的设置/拆卸函数。
编辑:赏金现已可用。必须有更好的方法,或者一个 GUI 测试运行器来为你处理它或其他东西。如果您在测试驱动环境中使用 QtTest,请告诉我什么对您有用。 (脚本、测试运行程序等)
I'm just starting to use QTestLib. 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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过将测试名称传递为 命令行参数:
它也将运行所有 inits/cleanups。不幸的是,不支持通配符/模式匹配,因此要运行以给定字符串开头的所有情况(我假设这就是“在整个类中运行测试”的意思),您必须创建脚本(Windows批处理/ bash/perl/whatever)调用:
解析结果并使用第一种语法运行选定的测试。
要运行所有情况,只需不要传递任何参数:
You can run only selected test cases (test methods) by passing test names as command line arguments :
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:
parses the results and runs selected tests using first syntax.
To run all cases, just don't pass any parameter:
OP 请求的三个功能现在已集成到 Qt Creator 中。
将自动扫描项目以进行测试,并将它们显示在“测试”窗格中。屏幕截图左下角:
每个测试和相应的数据都可以通过单击复选框来启用。
上下文菜单允许运行所有测试、一类的所有测试、仅选定的测试或仅一个测试。
按要求。
测试结果也可以从 Qt Creator 获得。颜色指示器将显示每个测试的通过/失败,以及调试消息等附加信息。
与 Qt Creator 结合使用,每个测试用例使用
QTEST_MAIN
宏将会很好地工作,因为每个编译的可执行文件都会由 Qt Creator 自动调用。有关更详细的概述,请参阅 Qt Creator 的运行自动测试部分手动的。
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:
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.