如何使用参数化测试用例
How to use parameterized test cases?
我正在尝试将参数化测试与将 POD 作为参数的类一起使用。我已经到了这个阶段:
struct TestParameters : public ::testing::TestWithParam<parameters> {
parameters params;
virtual void SetUp() {
params.username = "username";
params.host = "192.168.0.254";
}
};
TEST_P(TestParameters, connect) {
std::error_code ec;
std::unique_ptr<connection> connection = make_connection(GetParam(), ec);
ASSERT_FALSE(ec);
ec = connection->connect();
ASSERT_FALSE(ec);
}
INSTANTIATE_TEST_CASE_P(postgresql_tcp, connection, ::testing::Values());
我的问题是,如何通过INSTANTIATE_TEST_CASE_P
传递我需要的值parameters
以及如何将有效的parameters
实例传递给make_connection()
?
看起来你应该做一些类似的事情
INSTANTIATE_TEST_CASE_P(postgresql_tcp, connect,
::testing::Values(parameters{"username", "192.168.0.254"}
//, parameters{ other params here }
));
或者,您可以将std::vector<parameters>
声明为可以动态计算的全局,然后将该向量的迭代器传递给::testing::Values()
另外,请注意,您的夹具类中不需要杆件params
,因为该参数将由 Google Test 通过 GetParam()
自动提供
相关文章:
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 从父数组测试用例构造二叉树失败
- 在Raspbian上编译pybind11测试用例时出现致命错误
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 某些测试用例未通过
- 如何在多个 Catch2 测试用例中检查相同的条件
- 谷歌启动2018,测试用例中的整数错误
- 用于查找连续子数组的最大总和的代码使测试用例失败
- 查找不适用于 c++ 中特定测试用例的最长子字符串
- 测试用例状态为失败,但返回的值为 true
- kill syscommand 在 Catch2 测试用例中失败
- 大型测试用例中C++ dfs 问题中的小错误
- 为什么在输入的第一行输入测试用例数量后得到垃圾值?
- C++ Catch 是否有类似 NUnit 的测试用例的东西,具有多个参数/输入选项
- 如何修复此代码对几个测试用例的错误答案?
- 所有测试用例都将小数点转换为二进制数
- C++回文检查解决方案被一个测试用例跳闸
- 测试用例大小为 10 的向量失败
- 在测试用例中使用gtest特定的参数
- 在Google test参数化测试用例(' TEST_P ')中访问测试信息