![](/img/trans.png)
[英]How to run Parameterized Tests with fixture member values in Google Test (gtest)?
[英]Number of values in a parameterized google test
我正在將Google測試與參數化測試類一起使用。 我提供了測試用例的字符串列表,並且我知道我可以使用GetParam()
訪問每個值。 另外,我想確保所有標志都被覆蓋,因此我需要知道測試用例中標志的數量是否與可用標志的數量相同。
這樣的事情。
INSTANTIATE_TEST_CASE_P(Actions, TestActions
, ::testing::Values
(
"FLAG1"
, "FLAG2"
, "FLAG3"
)
);
TEST_F(TestActions, ActionCount)
{
// Check if a testcase was forgotten
EXPECT_EQ(gActions.size(), ParamCount());
}
TEST_P(TestActions, ActionEnabled)
{
string action = GetParam();
... do something here with param.
}
TEST_P(TestActions, ActionDisabled)
{
string action = GetParam();
... do something here with param.
}
像往常一樣,在遇到此類問題時,直到發布該問題並且找到解決方案后不久,我才找到解決方案。
解決這個問題的基本思路是我從這個問題及其答案中獲得的。 Google使用整體向量測試ValuesIn
因此,為了完善起見,希望其他人可以找到滿意的解決方法,我在這里發布了我的解決方案。
static std::vector<std::string> getKnownActions()
{
std::vector<std::string> actions = { "FLAG1", "FLAG2", "FLAG3"};
return actions;
}
INSTANTIATE_TEST_CASE_P(Actions, TestActions, ::testing::ValuesIn(getKnownActions()));
TEST_F(TestActions, ActionCount)
{
EXPECT_EQ(gActions.size(), getKnownActions().size());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.