Is there a way of passing both a type and a string to a parametrized test using google's test.
I would like to do:
template <typename T>
class RawTypesTest : public ::testing::TestWithParam<const char * type> {
protected:
virtual void SetUp() {
message = type;
}
};
TEST_P(RawTypesTest, Foo) {
ASSERT_STREQ(message, type);
ParamType * data = ..;
...
}
Thanks in advance
I did not research what TYPED_TEST_P family of macros does internally, but I find using them extra complicated for the goal. You could achieve the same simply encoding the parameter as part of the type.
then all you need to do is in the types to replace your class with the ParamTextFixture
Value parameterized tests won't work for passing type information; you can only do that with typed or type parameterized tests. In both cases you'll have to package your type and string information into special structures. Here is how to do it with type-parameterized tests:
And now you have to define the parameter structures and instantiate the tests for them:
You can use a macro to simplify definition of your parameter types:
Then definitions of parameter structs become much shorter:
This is quite complicated but there is no easy way to do this. My best advice is to try re-factor your tests to avoid requiring both type and value information. But if you must, here is the way.