Create tests at run-time (google test)
Use value-parameterized tests:
typedef std::pair<std::string, std::string> TestParam;
class ParserTest : public testing::TestWithParam<TestParam> {};
TEST_P(ParserTest, ParsesAsExpected) {
test_parameters = yaml_conf.get_parameters(GetParam().first,
GetParam().second);
g_parser.parse(test_parameters);
ASSERT_TRUE(g_env.parsed_as_expected());
}
INSTANTIATE_TEST_CASE_P(
GeneralAndSpecial,
ParserTest,
testing::Values(
TestParam("General", "GeneralTestCase")
TestParam("Special", "SpecialTestCase1")
TestParam("Special", "SpecialTestCase2")));
You can read the list of test cases from disk and return it as a vector:
std::vector<TestParam> ReadTestCasesFromDisk() { ... }
INSTANTIATE_TEST_CASE_P(
GeneralAndSpecial, // Instantiation name can be chosen arbitrarily.
ParserTest,
testing::ValuesIn(ReadTestCasesFromDisk()));
I have added two classes DynamicTestInfo
& ScriptBasedTestInfo
as well as RegisterDynamicTest
function into google unit test. It requires C++17 at least (haven't analyzed backporting to C++11 or C++14) - it allow to create google unit tests dynamically / at run-time slightly simpler than current google API's.
For example usage could be something like this:
https://github.com/tapika/cppscriptcore/blob/f6823b76a3bbc0ed41b4f3cf05bc89fe32697277/SolutionProjectModel/cppexec/cppexec.cpp#L156
But this requires modified google test, see this file for example:
https://github.com/tapika/cppscriptcore/blob/f6823b76a3bbc0ed41b4f3cf05bc89fe32697277/SolutionProjectModel/logTesting/gtest/gtest.h#L819
I will try to merge changes to official google test repository.
I have changed also how tests are reported to user application (using <loc>
tag)
but that one requires modified google test adapter for Visual studio, for more information see following youtube video for more explanation how things works.
https://www.youtube.com/watch?v=-miGEb7M3V8
Using newer GTA you can get file system listing in test explorer, for example like this: