can I disable only part of typed tests?

1,783 views
Skip to first unread message

ndori

unread,
Jun 1, 2011, 3:56:12 AM6/1/11
to Google C++ Testing Framework
Hi,
I'm using Google test for a little while by now, and I've got a
problem that I'm not sure if Google test currently know how to handle.

so this is the scenario :

I have a typed test suite which run on 2 different implementations,

however, I have some tests for features that a not yet implemented and
thus are disabled for the current moment.

I've come to a point which for one implementation this features are
implemented and for the other they are still not.

so I wan't this tests to be DISABLED for some implementations and for
others to be enabled.

is there a way to do it in Google test?

so the problem is actually that DISABLED_ prefix is disabling a test,
but in some cases (i.e. typed tests and value parameterized test) a
certain test represent more then one test , but DISABLED_ is disabling
all of the tests it represent....

I can think of several solutions to this problem, but if there is a
way to do it with Google test (and there should be one) I really
prefer it.

thx, Nitzan

David Roger

unread,
Nov 25, 2011, 7:27:29 AM11/25/11
to googletes...@googlegroups.com
Hi,

I am posting in this thread because I think I need the same feature as the original poster.

I have a test case and I'd like to run it on two implementations.
I could use either parameterized tests (the parameter would be a factory) or type-parameterized tests.
The problem is that one implementation is not complete and fail at some of the tests.

I'd like to be able to disable individual tests in the test case, only for that implementation.
Currently, INSTANTIATE_TYPED_TEST_CASE_P instantiates all the tests of the test case, which leads to failures.

A possible solution would be to split the tests case in several test cases, but it seems to me that it is not very convenient:
- I would need to replicate the fixture class, because it cannot be shared across test cases.
- If I split the test case in two (the tests that pass on both implementations, and the tests that pass only on one), I will need to change the splitting every time the implementation changes and passes new tests.
- If I split the case in multiple cases in order to have only one test per case, I am afraid of the code becoming difficult to understand because I would need to introduce new macros and such to handle the fixture classes replication

Is there any better solution?

Vlad Losev

unread,
Nov 25, 2011, 1:59:20 PM11/25/11
to googletes...@googlegroups.com
You can simply block the test from execution. It may be as simple as this:

TEST_P(TestCaseName, TestName) {
  if (test_should_be_disabled) {
    printf("NOTE: The test TestCaseName.TestName has been manually disabled\n.");
    return;
  }
  // Do the test
}

The question is how to implement the condition. For value-parameterized tests it's fairly simple:

if (GetParam() == bad_param_value) ...

for type-parameterized tests, it's a little bit more involved. You need to define a template type providing a value and specialize it for the types you want to exclude from the test:

template <typename T> struct BadTypeSelector {
  enum SelectorType { value = true };
};

class BadType {};

template <> struct BadTypeSelector<BadType> {
  enum SelectorType { value = false };
};

then the condition becomes

if (BadTypeSelector<TypeParam>::value) ...

If you may also wrap these definitions and checks into macros to make the code shorter. 

HTH,
Vlad
Reply all
Reply to author
Forward
0 new messages