简体   繁体   中英

How does google test make test sequence

How google-test makes test sequence (or order of test case execution) for testing test cases?

Suppose I have 5 test cases.

TEST(First, first)
TEST(Secnd, secnd)
TEST(Third, third)
...
TEST(Fifth, fifth)

How google-test test above test cases? I mean in what sequence? Or can we provide any test sequence?

By default it will test them in the order it finds them at link time, which will depend upon your tools.

You can select which tests to run , such as a subset, or a single test.

There is also an option to run them in a random order .

The advanced reference pages for googletest in the chapter Shuffling the Tests tells :

By default, Google Test uses a random seed calculated from the current time. Therefore you'll get a different order every time.

This is actually a good way of unit testing, since tests should not depend on the order of execution.

As far as I know, there are no ways of setting the order of tests execution. The only parameter you can set is the seed, used to set the same order of execution.

By default they run in the declaration order. As said by other, you have to provide the flag --gtest_shuffle to shuffle them.

Even if you can guess some pattern for the order of execution (as written, or linked) you shouldn't depend on that.

It would be repeated on different executions, though. If you don't want it to happen, you can use --gtest-shuffle . That runs the test on a random order, according to a random seed.

In case of failure, you can use --gtest_random_seed= with that number and repeat the exact sequence (to investigate why it failed).

That said, the randomness is not complete:

  • Test suites will be run in a random order
  • Tests within a test suite will be run in a random order

If not run in this way, SetUpTestSuite and TearDownTestSuite methods would be mixed. You don't need a fixture for this grouping to happen, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM