c++ - Catch 测试框架问题:无法使用 Catch::Session()

标签 c++ session testing frameworks catch-unit-test

我在编写一些测试的 C++ 文件中遇到此错误:

error: no member named 'Session' in namespace 'Catch'
        testResult = Catch::Session().run(test_argc, test_argv);
                     ~~~~~~~^

查看 catch.hpp 单个头文件,我注意到应该实现 Session() 成员函数的代码是灰色的,可能是因为我找不到某个地方的 #ifdef。

是否有任何宏可以设置为使用 session 类?

捕获版本:1.5.3 和 1.5.6。

引用:https://github.com/philsquared/Catch/blob/master/docs/own-main.md

最佳答案

您正试图从一个文件中调用 Catch::Session 的构造函数,而您没有定义要执行的自己的 main。根据documentation on defining your own main ,应该只有一个 Catch::Session 实例:

Catch::Session session; // There must be exactly once instance

Catch 可能会阻止在翻译单元中构造 Catch::Session,因为它不能在自定义 main 定义中使用(因为这是它应该的地方被使用),以防止您在编译时犯的错误。

关于c++ - Catch 测试框架问题:无法使用 Catch::Session(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38105783/

相关文章:

c - 使用一些输入测试 C 程序

unit-testing - npm 运行自定义测试 - sendHttpRequest 失败 non200Response

testing - 当渲染器进程消耗太多内存时 Docker 崩溃了?

c++ - 我刚开始使用 Eigen 矩阵代数库,旨在创建数据集的相似矩阵,有什么建议吗?

c++ - 使用一对作为另一个函数的参数

javascript - 使用 Javascript 访问 ASP session 变量

php - 在 laravel 的自定义中间件中使用 session

c++ - OpenGL EGL 在 docker 的 eglGetDisplay 返回 0x300c (EGL_BAD_PARAMETER)

android - 如何设置eclipse在构建过程中不删除某些文件

session - 如何在 JSF 2.0 中使 session 失效?