[英]Run tests in specific order
I've installed in Visual Studio 2013 the Google Test runner extension. 我在Visual Studio 2013中安装了Google Test runner扩展。
Now I have a test project 现在我有一个测试项目
TestProject
|
|-InitializationTests.cpp
|-RunningTests.cpp
I want to run all test cases inside InitializationTests.cpp
before tests inside RunnintTests.cpp
. 我想在RunnintTests.cpp
测试之前运行InitializationTests.cpp
所有测试用例。 How can I accomplish this? 我怎么能做到这一点?
Sure You Can! 你当然可以! It's a program not concrete. 这是一个不具体的计划。
main.cpp: main.cpp中:
::testing::GTEST_FLAG(filter) = "tA.*";
RUN_ALL_TESTS();
::testing::GTEST_FLAG(filter) = "tB.*";
RUN_ALL_TESTS();
::testing::GTEST_FLAG(filter) = "tC.*";
return RUN_ALL_TESTS();
It will run in the next order: 它将按下一个顺序运行:
tA.*,
tB.*,
tC.*,
Test framework normally do not allow to control the order of tests, because it is a general requirement that tests are independant from each other. 测试框架通常不允许控制测试的顺序,因为一般要求测试彼此独立。
But you can always run a single test, and Google Test has a powerful option to control which tests are to be run. 但是你可以随时运行一个测试,而Google Test有一个强大的选项来控制要运行的测试。 From Google Test advanced guide : If you set the GTEST_FILTER environment variable or the --gtest_filter flag to a filter string, Google Test will only run the tests whose full names (in the form of TestCaseName.TestName) match the filter 来自Google Test高级指南 : 如果您将GTEST_FILTER环境变量或--gtest_filter标志设置为过滤字符串,Google Test将仅运行其全名(以TestCaseName.TestName形式)与过滤器匹配的测试
For your use case, supposing you execute all tests in your test project by calling : 对于您的用例,假设您通过调用以下方法在测试项目中执行所有测试:
TestProject
you could run only initialization tests by running : 你可以通过运行只运行初始化测试:
TestProject --gtest_filter=InitializationTests.*
(provided InitialisationTests.cpp
contains tests for test case InitializationTests
) (提供InitialisationTests.cpp
包含试验测试用例InitializationTests
)
Tests order should be independent. 测试顺序应该是独立的。 And GTest does not allow to control the order. 并且GTest不允许控制订单。 Even more: tests can be run in parallel 更多:测试可以并行运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.