c++ - 包含主项目中的文件时单元测试项目中的错误

标签 c++ visual-studio unit-testing visual-studio-2015 compiler-errors

我目前正在学习 Visual Studio 2015 中的单元测试,但我发现很难找到关于该主题的好资源。

我在与主项目相同的解决方案中设置了一个 C++ native 单元测试项目。然后我将主项目设置为测试项目中的引用。

我的问题是,当我在测试中包含来自主项目的文件时,几乎每个函数都会发出类似这样的编译器错误。

Errors

这是测试类

#include "stdafx.h"
#include "CppUnitTest.h"

#include <Windows.h>
#include <Util\fileutil.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;


namespace EngineTest
{       
using namespace Engine;
TEST_CLASS(EngineTests)
{
public:

    TEST_METHOD(UnitTestTest)
    {
        int i = 1;
        Assert::IsTrue(i == 1);
    }

    TEST_METHOD(FilePathSplit)
    {
        FileUtils testClass;
        std::string examplePath = "./FolderOne/FolderTwo/File.file";
        std::string exampleName = "File.file";
        std::set<char> delims{ '\\', '/' };
        std::string fileName = testClass.test_splitpath(examplePath, delims).back();
        Assert::AreSame(fileName, exampleName);

    }

};
}

构建工作正常,所以我认为这是一个没有加载依赖项的问题,我尝试将所有 header 添加到 stdafx 中,但这并没有改变任何东西。

感谢任何帮助。

最佳答案

好吧,这是一个愚蠢的问题。

主要项目设置为支持多字节字符集,另一个设置为使用 Unicode。因此,在我尝试将 const char* 转换为 win32 格式时出现的所有错误,它都不喜欢。

属性 -> 常规 -> 字符集

关于c++ - 包含主项目中的文件时单元测试项目中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49962253/

相关文章:

visual-studio - Visual Studio 中特定解决方案的默认浏览器

visual-studio - 保留以前的 "find all references"结果

c# - 如何使用 FakeItEasy 断言未调用方法

android - 如何为 Android 自动化生成报告

c++ - 使用 ffmpeg.dll 或 avcodec.dll 将视频文件转换为 TIFF? "on-the-fly"可能吗?

java - 在 java/c++/c/actionscript-3 应用程序中使用静态变量的最佳方法是什么?

c++ - 如何在 Visual Studio 中禁用自动插入内联关键字?

PHPUnit 错误 fatal error :调用未定义的方法 Mock_Game_073a8e20::method()

c++ - Winsocks 只接收一行

c++ - 是否可以简单地序列化 C++ 对象