【问题标题】:Errors in Unit Test project when including file from main project包含来自主项目的文件时单元测试项目中的错误
【发布时间】:2018-10-02 09:18:18
【问题描述】:

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

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

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

这是测试类

#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);

    }

};
}

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

感谢任何帮助。

【问题讨论】:

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


    【解决方案1】:

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

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

    属性 -> 常规 -> 字符集

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 2015-02-28
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 2011-09-08
      相关资源
      最近更新 更多