简体   繁体   English

单元测试。 如何在main()中运行测试

[英]Unit tests. How to run tests in the main()

I am trying to run a test in the main function, but the error "you cannot overload the main () function"is displayed. 我试图在主函数中运行测试,但显示错误“你不能重载main()函数”。

#define CATCH_CONFIG_RUNNER // -- main() создавать нужно --
#include "catch.hpp"
int main(int argc, char* argv[])
{
    setlocale(LC_ALL, "Russian");
    int result = Catch::Session().run(argc, argv);
    system("pause");
    return result;
}

You should use Catch in some other way. 你应该以其他方式使用Catch Something like that worked for me: 这样的东西对我有用:

#include <iostream> // some standard includes, whatever you need

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE("My first test") {
    // --- test code here ---
}

TEST_CASE("My second test") {
    // --- test code here ---
}

Try the framework's tutorial to learn more =) 尝试框架的教程了解更多=)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM