Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run tests in specific order

I've installed in Visual Studio 2013 the Google Test runner extension.

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. How can I accomplish this?

like image 445
Jepessen Avatar asked Jan 14 '15 07:01

Jepessen


People also ask

What can we do to make your tests run in specific order?

When you have multiple test cases and want them to run in a particular order, you can use the Priority attribute to set test priority in TestNG. The test cases get executed following an ascending order in the priority list, and hence, test cases with lower priority will always get executed first.

How do I run a test order in a specific TestNG?

First of all, beforeSuite() method is executed only once. Lastly, the afterSuite() method executes only once. Even the methods beforeTest(), beforeClass(), afterClass(), and afterTest() methods are executed only once. beforeMethod() method executes for each test case but before executing the test case.

What is the sequence of test execution?

In JUnit, the execution sequence of the same project is: InitTestCase (setUp) TestCase1 (testMethod1) EndTestCase (tearDown)


2 Answers

Sure You Can! It's a program not concrete.
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.*,  
like image 76
jstar Avatar answered Sep 30 '22 17:09

jstar


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. 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

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)

like image 45
Serge Ballesta Avatar answered Sep 30 '22 17:09

Serge Ballesta