如何使用Catch2测试Visual Studio中的大型项目

发布于 2025-01-25 10:34:11 字数 883 浏览 1 评论 0原文

我在2019年的Visual Studio中有一个大项目。
我想通过catch2库对其进行测试。

我想知道如何正确包含我的项目吗?

,在main.cpp中。

#include <header1>
#include <header2>
#define CATCH_CONFIG_MAIN
#include <catch/catch.hpp> // header only library

void function_1()
{
   // do something
}

void function_2()
{
   // do something
}

// int main()
// {
TEST_CASE("My test number 1", "[Test1]")
{
   function_1();
   function_2();

}
// return 0;
// }

例如 喜欢

main.obj : error LNK2001: unresolved external symbol "public: __cdecl Catch::AutoReg::AutoReg(struct Catch::ITestInvoker *,struct Catch::SourceLineInfo const &,class Catch::StringRef const &,struct Catch::NameAndTags const &)" (??0AutoReg@Catch@@QEAA@PEAUITestInvoker@1@AEBUSourceLineInfo@1@AEBVStringRef@1@AEBUNameAndTags@1@@Z).

这样,我应该如何正确编写代码以使用catch2库?

I have a big project in Visual Studio 2019.
And I want to test it by Catch2 library.

I'd like to know how to include this library correctly in my project?

For example, in main.cpp I do:

#include <header1>
#include <header2>
#define CATCH_CONFIG_MAIN
#include <catch/catch.hpp> // header only library

void function_1()
{
   // do something
}

void function_2()
{
   // do something
}

// int main()
// {
TEST_CASE("My test number 1", "[Test1]")
{
   function_1();
   function_2();

}
// return 0;
// }

After that I get a lot of errors like

main.obj : error LNK2001: unresolved external symbol "public: __cdecl Catch::AutoReg::AutoReg(struct Catch::ITestInvoker *,struct Catch::SourceLineInfo const &,class Catch::StringRef const &,struct Catch::NameAndTags const &)" (??0AutoReg@Catch@@QEAA@PEAUITestInvoker@1@AEBUSourceLineInfo@1@AEBVStringRef@1@AEBUNameAndTags@1@@Z).

So, how should I write my code correctly to use Catch2 library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文