I have a function which reads out all files in a selected directory.
std::vector<std::string> getAllFilesInDirectory(const std::string_view strDirectory);
Now I'd like to run my tests on each element of that vector. My test fixture is pretty straight forward.
class myTestfixture: public ::testing::TestWithParam<std::string>
{
public:
myTestfixture();
~myTestfixture() override;
};
Now I'd like to pass each element of the vector to my tests. I know I can pass single explicit values to :testing::Values, but passing a stl container does not work.
INSTANTIATE_TEST_CASE_P(
myTest,
myTestfixture,
::testing::Values(
getAllFilesInDirectory("myDir")
));
TEST_P(myTestfixture, ValidTest)
{
//test something
}
Is it even possible to pass containers as a parameter source to gtest?
CodePudding user response:
You have almost done it but with a small mistake. Try to use ValuesIn()
instead of Values()
.
INSTANTIATE_TEST_CASE_P(
myTest,
myTestfixture,
::testing::ValuesIn(
getAllFilesInDirectory("myDir")
));