代码之家  ›  专栏  ›  技术社区  ›  Calum McManus

包含主项目中的文件时,单元测试项目中出现错误

  •  1
  • Calum McManus  · 技术社区  · 6 年前

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

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

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

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

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

    非常感谢您的帮助。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Calum McManus    6 年前

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

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

    属性->常规->字符集