Can Googletest value-parameterized with multiple, different types of parameters match mbUnit flexibility?

前端 未结 2 2094
孤城傲影
孤城傲影 2020-12-28 15:47

I\'d like to write C++ Google tests which can use value-parameterized tests with multiple parameters of different data types, ideally matching the complexity of the followin

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-28 16:41

    Yes, there's a single parameter. You can make that parameter be arbitrarily complex, though. You could adapting the code from the documentation to use you Row type, for example:

    class AndyTest : public ::testing::TestWithParam {
      // You can implement all the usual fixture class members here.
      // To access the test parameter, call GetParam() from class
      // TestWithParam.
    };
    

    Then define your parameterized test:

    TEST_P(AndyTest, CountViaDirectSQLCommand)
    {
      // Call GetParam() here to get the Row values
      Row const& p = GetParam();
      std::string dbFilePath = testDBFullPath(p.dbname);
      {
        StAnsi fpath(dbFilePath);
        StGdbConnection db(p.fpath);
        db.Connect(p.fpath);
        int result = db.ExecuteSQLReturningScalar(StAnsi(p.command));
        EXPECT_EQ(p.numRecs, result);
      }
    }
    

    Finally, instantiate it:

    INSTANTIATE_TEST_CASE_P(InstantiationName, AndyTest, ::testing::Values(
      Row("Empty.mdb", "select count(*) from collar", 0),
      Row("SomeCollars.mdb", "select count(*) from collar", 17),
      Row("SomeCollars.mdb", "select count(*) from collar where max_depth=100", 4)
    ));
    

提交回复
热议问题