How do I run individual tests or test groups in main to allow test ordering ?

1,822 views
Skip to first unread message

Aaron Gray

unread,
May 2, 2016, 8:58:32 PM5/2/16
to Google C++ Testing Framework
Hi,

How do I run individual tests or test groups in main to allow test ordering ?

At the moment as test order seems to be alphabetical as far as I can tell I am running some complex test before the simpler ones.

Rather than 'RUN_ALL_TESTS()' is there a way to invoke specific tests so I can order them please ?

Many thanks in advance,

Aaron Gray





Josh Kelley

unread,
May 2, 2016, 10:35:37 PM5/2/16
to Aaron Gray, Google C++ Testing Framework
Internally, tests are registered using static constructors, so they're typically run in link order. (This should be considered an implementation detail.) Google Test doesn't directly provide a means of specifying a test order, but you can use the --gtest_filter flag to run a subset of tests:


-- 
Josh Kelley

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Gray

unread,
May 5, 2016, 2:12:56 PM5/5/16
to Google C++ Testing Framework, aaron...@gmail.com
On Tuesday, 3 May 2016 03:35:37 UTC+1, Josh Kelley wrote:
Internally, tests are registered using static constructors, so they're typically run in link order. (This should be considered an implementation detail.) Google Test doesn't directly provide a means of specifying a test order, but you can use the --gtest_filter flag to run a subset of tests:


Wow that's pretty annoying ! Gonna have to stick a prefix on the test names like 'TestN_*' !


-- 
Josh Kelley

On Sun, May 1, 2016 at 12:03 PM, Aaron Gray <aaron...@gmail.com> wrote:
Hi,

How do I run individual tests or test groups in main to allow test ordering ?

At the moment as test order seems to be alphabetical as far as I can tell I am running some complex test before the simpler ones.

Rather than 'RUN_ALL_TESTS()' is there a way to invoke specific tests so I can order them please ?

Many thanks in advance,

Aaron Gray





--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframework+unsub...@googlegroups.com.

Keith Ray

unread,
May 5, 2016, 2:47:23 PM5/5/16
to Aaron Gray, Google C++ Testing Framework
You could also look at the googletest source code that implements "--gtest_shuffle" and implement your own option, perhaps called "--gtest_sort_by_names".
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.

Keith Ray

unread,
May 5, 2016, 2:49:34 PM5/5/16
to Aaron Gray, Google C++ Testing Framework
quoting https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-a-subset-of-the-tests 

Shuffling the Tests

You can specify the --gtest_shuffle flag (or set the GTEST_SHUFFLE environment variable to 1) to run the tests in a program in a random order. This helps to reveal bad dependencies between tests.

By default, Google Test uses a random seed calculated from the current time. Therefore you'll get a different order every time. The console output includes the random seed value, such that you can reproduce an order-related test failure later. To specify the random seed explicitly, use the --gtest_random_seed=SEED flag (or set the GTEST_RANDOM_SEED environment variable), where SEED is an integer between 0 and 99999. The seed value 0 is special: it tells Google Test to do the default behavior of calculating the seed from the current time.

If you combine this with --gtest_repeat=N, Google Test will pick a different random seed and re-shuffle the tests in each iteration.

Availability: Linux, Windows, Mac; since v1.4.0.

Aaron Gray

unread,
May 5, 2016, 4:43:45 PM5/5/16
to Keith Ray, Google C++ Testing Framework
Keith,

Okay I will look into that over the weekend.

Thanks !

Aaron


On 5 May 2016 at 19:47, Keith Ray <keit...@gmail.com> wrote:
You could also look at the googletest source code that implements "--gtest_shuffle" and implement your own option, perhaps called "--gtest_sort_by_names".
On 2016 May 05, at 11:12 AM, Aaron Gray <aaron...@gmail.com> wrote:

On Tuesday, 3 May 2016 03:35:37 UTC+1, Josh Kelley wrote:
Internally, tests are registered using static constructors, so they're typically run in link order. (This should be considered an implementation detail.) Google Test doesn't directly provide a means of specifying a test order, but you can use the --gtest_filter flag to run a subset of tests:


Wow that's pretty annoying ! Gonna have to stick a prefix on the test names like 'TestN_*' !


-- 
Josh Kelley

On Sun, May 1, 2016 at 12:03 PM, Aaron Gray <aaron...@gmail.com> wrote:
Hi,

How do I run individual tests or test groups in main to allow test ordering ?

At the moment as test order seems to be alphabetical as far as I can tell I am running some complex test before the simpler ones.

Rather than 'RUN_ALL_TESTS()' is there a way to invoke specific tests so I can order them please ?

Many thanks in advance,

Aaron Gray






--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages