I have a Parser that has to be tested. There are lots of test input files to this Parser. The expected behaviour of the Parser is tested by comparing output of the Parser with corresponding pregenerated files.
Currently I'm processing YAML file in the test to get input files, expected files and their's description (in case of failure this description will be printed).
There are also parameters of the Parser that should be tested on the same input.
So, I need to form the following code in the test:
TEST(General, GeneralTestCase)
{
test_parameters = yaml_conf.get_parameters("General", "GeneralTestCase");
g_parser.parse(test_parameters);
ASSERT_TRUE(g_env.parsed_as_expected()) << g_env.get_description("General", "GeneralTestCase");
}
TEST(Special, SpecialTestCase1)
{
test_parameters = yaml_conf.get_parameters("Special", "SpecialTestCase1");
g_parser.parse(test_parameters);
ASSERT_TRUE(g_env.parsed_as_expected()) << g_env.get_description("Special", "SpecialTestCase1");
}
TEST(Special, SpecialTestCase2)
{
test_parameters = yaml_conf.get_parameters("Special", "SpecialTestCase2");
g_parser.parse(test_parameters);
ASSERT_TRUE(g_env.parsed_as_expected()) << g_env.get_description("Special", "SpecialTestCase2");
}
It is easy to see the repetition of the code. So I feel there is a way to automate these tests.
Thanks in advance.
::testing::InitGoogleTest();
. SinceReadTestCasesFromDisk()
will probably need to access some argument passed by cmd arguments, the call to::testing::InitGoogleTest();
will need probably to be moved to a later point in the main function. – Georgetown