简体   繁体   中英

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.

#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. 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 =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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