Enabling and disabling long tests

926 views
Skip to first unread message

Hamish

unread,
Jan 12, 2010, 10:53:25 AM1/12/10
to Google C++ Testing Framework
Dear fellow Google Test users,

I have a test suite which includes several tests that take quite a
long time to complete. I would like these to be disabled by default,
but they should run if I specify a certain command line flag. They
would basically behave in exactly the same way as Google Test's
"disabled" test cases. Thus I *could* use the disabled test feature
already provided, but I don't want to because that would mean that I
would effectively lose the functionality of optionally disabling tests
(because every time I disable a broken test, then try to run the test
program with the --gtest_also_run_disabled_tests flag, I will have
to sit through the long tests too). I've adopted the policy of having
all these long tests include the string "LONG_TEST" in their names.
With that, the best solution I've come up with so far is the following
main() function:

---BEGIN CODE---
#include <gtest/gtest.h>

int main(int argc, char *argv[])
{
bool run_long_tests = false; // Read this from argv

if ( ! run_long_tests)
::testing::GTEST_FLAG(filter) = ":-:*LONG_TEST*";

::testing::InitGoogleTest(&argc, argv);

/*
if ( ! run_long_tests)
::testing::GTEST_FLAG(filter) += ":-:*LONG_TEST*";
*/

return RUN_ALL_TESTS();
}
---END CODE---

But that doesn't work if the user sets another filter on the command
line: the user's filter will overwrite the one I set. What I would
like to do is replace the 'if' statement above the call to
InitGoogleTest(...) with the one in the comment immediately after
it. That would solve all my problems, but unfortunately whatever
type ::testing::GTEST_FLAG(filter) is, it doesn't overload the +
and += operators so it seems I can't modify the flags after they're
read by InitGoogleTest(...).

Does anyone have any ideas on how I could get this to work?

Cheers,
Hamish.

Alexander Demin

unread,
Jan 12, 2010, 11:50:19 AM1/12/10
to Hamish, Google C++ Testing Framework
So we could end to not just a DISABLED flag of a test but also with the set of levels of disabled tests. It would be quite general approach providing the ability to disable and enable groups of tests.

Regards,
Alexander
Reply all
Reply to author
Forward
0 new messages