以下是一个示例代码:
private static bool PermissionComparison(GuildPermissions targetGuildPerms, GuildPermissions userGuildPerms)
{
//True if the target has a higher role.
bool targetHasHigherPerms = false;
//If the user is not admin but target is.
if(!userGuildPerms.Administrator && targetGuildPerms.Administrator) {
//The target has higher permission than the user.
targetHasHigherPerms = true;
} else if(!userGuildPerms.ManageGuild && targetGuildPerms.ManageGuild) {
targetHasHigherPerms = true;
} else if(!userGuildPerms.ManageChannels && targetGuildPerms.ManageChannels) {
targetHasHigherPerms = true;
} else if(!userGuildPerms.BanMembers && targetGuildPerms.BanMembers) {
targetHasHigherPerms = true;
} else if(!userGuildPerms.KickMembers && targetGuildPerms.KickMembers) {
targetHasHigherPerms = true;
}
return targetHasHigherPerms;
}
我希望得到4个测试(Test1的2个实例和Test2的2个实例),但是运行了8个测试。为什么?如何解决?
答案 0 :(得分:1)
INSTANTIATE_TEST_CASE_P(prefix, fixture, generator)
为每个使用相同fixture
类型的参数化测试用例注册要运行的测试。 prefix
仅用于参数化测试的构建名称,它们出现在输出中,可以与--gtest-filter
命令行参数一起使用。
因此,如果您希望Test1
和Test2
使用不同的参数值集运行,那么您需要强制它们为不同的灯具类型:
// ...
struct MyFixtureForTest1 : public MyFixtureWithNumber {};
struct MyFixtureForTest2 : public MyFixtureWithNumber {};
TEST_P(MyFixtureForTest1, Test1)
{
std::cout << "Test1 with param: " << GetParam() << std::endl;
}
INSTANTIATE_TEST_CASE_P(SmallValues, MyFixtureForTest1, ::testing::Values(0,3));
TEST_P(MyFixtureForTest2, Test2)
{
std::cout << "Test2 with param: " << GetParam() << std::endl;
}
INSTANTIATE_TEST_CASE_P(LargeValues, MyFixtureForTest2, ::testing::Values(5, 7));