how to use GetParam() in googletest
时间: 2024-05-05 17:18:11 浏览: 6
To use GetParam() in googletest, you first need to define a test fixture class that inherits from testing::TestWithParam<T>, where T is the type of the parameter you want to pass. Inside the fixture class, you can access the value of the parameter using GetParam(). For example:
```
class ExampleTest : public testing::TestWithParam<int> {
public:
// Set up code here
};
TEST_P( ExampleTest, Test1 ) {
int param_value = GetParam();
// Perform tests using param_value
}
INSTANTIATE_TEST_SUITE_P( TestSuite, ExampleTest, testing::Values(1, 2, 3) );
```
In this example, we define an ExampleTest fixture class that takes an integer parameter. Inside the Test1 test case, we retrieve the value of the parameter using GetParam(). Finally, we use INSTANTIATE_TEST_SUITE_P() to instantiate the test suite with a list of parameter values.