如何在多个 Catch2 测试用例中检查相同的条件
How to check the same condition in several Catch2 test cases
我必须在几个测试用例中检查某些条件(例如初始状态(。我不能在功能中使用CHECK
,如果可能的话,我想替换当前的宏。
#include "catch.hpp"
#define CHECK_INITIAL_STATE()
CHECK(first_condition);
CHECK(second_condition);
TEST_CASE("first_test") {
CHECK_INITIAL_STATE();
// do something
// restore state
CHECK_INITIAL_STATE();
}
Catch2 以一种非常优雅的方式内置了这个功能:
TEST_CASE("first_test") {
CHECK(first_condition);
CHECK(second_condition);
SECTION("do something 1") {
// this test is executed after the code outside of the section
}
SECTION("do something 2") {
// this test is executed after the code outside of the section
// but without executing the previous section
}
}
相关文章:
- 检查C++中的条件
- 如何在C++中使用 HRESULT 条件检查
- Vulkan 的传输队列系列功能和显卡支持:条件检查是否准确?
- 如何在多个 Catch2 测试用例中检查相同的条件
- 对于检查 >=0 终止条件时的循环索引类型
- "is defined"宏检查及其调用必须处于不同的条件下吗?
- 在if条件下,右或左改变值的相等性检查是否有任何区别
- 如何检查条件是否为 true 5 秒?
- C++未检查条件语句
- 通过检查条件并重新检查来获取锁定
- if 语句正在检查什么条件
- GDB在断点检查条件时失败
- 在 do-while 循环中初始化字符串将在检查条件之前跳转到它
- 虽然循环不检查条件,如果没有语句
- 将泛型子类上的检查条件分派到只知道基类的上下文中
- 循环中没有检查条件,但循环仍然终止C++
- template非类型参数:在编译时检查条件
- 返回 istream&对象以检查条件
- C++ - 返回循环开始而不检查条件
- 返回语句检查条件