在Visual C++ 2015中使用Catch2
Using Catch2 in Visual C++ 2015
我正在尝试使用 Catch 框架制作一个单元测试项目,但遇到了链接错误。
我已经设置了如下项目:
- 创建本机单元测试项目
- 将 Catch 添加到包含目录
- 将
#include <catch.hpp>
添加到 stdafx.h - 编写以下简单源文件
单元测试.cpp:
#include "stdafx.h"
namespace Catch2_Test
{
TEST_CASE("Y U no work")
{
REQUIRE(1);
}
}
用于将 Catch 集成到 Visual Studio
中请参考 ACCU 文章 将捕获测试框架集成到 Visual Studio 中,作者是 Malcolm Noyes
为了在预编译的标头中使用 Catch2,
参考 Catch2 问题 1061,其中 horenmar 举了一个例子。这些更改已作为 v2.1.0 的一部分发布
总之,给出的解决方案是:
// stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#define CATCH_CONFIG_ALL_PARTS
#include "catch.hpp"
// PCH-test.cpp:
#include "stdafx.h"
#undef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
#define CATCH_CONFIG_IMPL_ONLY
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
// tests1.cpp:
#include "stdafx.h"
TEST_CASE("FooBarBaz") {
REQUIRE(1 == 2);
}
问题是我从主分支克隆了 Catch2,而 VS 集成在 Catch 之外的一个分支上工作。
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- vs 2015 constexpr变量不恒定,但与2019相比还好吗
- 从VS 2015更新3更新到VS2015更新3 d后浮点计算行为不同的原因
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 如何实现自定义匹配器以检查 Catch2 中的对象相等性
- Qt Visual Studio 2015 加载项编译问题
- 如何在 Bazel 项目中设置 Catch2
- 包含在 <WinSock2> Visual Studio 2015 中时出现错误
- 如果所有部分都失败,Catch2 将再次运行测试
- 将 unordered_map 与 Catch2 谓词一起使用时类型不匹配
- 如何在多个 Catch2 测试用例中检查相同的条件
- 在 Windows 10 上的 Visual Studio 2015 中使用 _open 和 _setmode
- 如何在不进入 Visual Studio 2015 中的外部库的情况下单步执行我的代码 (F11)
- 为什么使用 <uint8_t>MSVC 2015 编译器的 std::vector::insert 比 std::copy 快 5 倍?
- c++ Visual Studio 2015 快捷方式,用于从选择代码中生成功能
- 为Catch2中的外部文本文件指定路径的最佳方式
- Visual Studio 2015资源视图和资源编译器使用不同的方法在项目目录中查找图标文件.如何修复
- Visual Studio 2015 中的调试速度很慢 -- 无法关闭页面堆?
- VisualStudio 2015 - 只计算命中,不停止
- 在Visual C++ 2015中使用Catch2