【问题标题】:Failed to Set up the execution context to run the test无法设置执行上下文来运行测试
【发布时间】:2017-02-13 01:30:29
【问题描述】:

这是我目前的设置:

  • 我有一组可以完美运行的单元测试
  • 我有一组库全部编译为静态 .lib
  • 单元测试项目编译为 .dll 并包含多个类

我最近添加了一个类,即MyCoolClass.h:

#include "AnotherBoringClass.h" // also inherits from BoringClass

class SuperCoolClass: public BoringClass
{
    /*
     * My super cool implementation
    */
protected:
    std::shared_ptr<AnotherBoringClass> myCoolPointer;
}

一切都很好,编译等等。但是当我尝试添加单元测试时:

#include "CppUnitTest.h"
#include "MyCoolClass.h"

TEST_CLASS(MyTestClass)
    {
    public:
        /*
         * Bunch of super cool -working- tests
        */
        TEST_METHOD(MyBrokenTest)
        {
            auto myVar = std::make_shared<MyCoolClass>();  // as soon as I comment this line everything works!!!
        }
    }

当我如上所述评论该行时,一切正常!我做错了什么?

我尝试过的:

  • This,但我将所有内容都放在同一个输出文件夹中。另外,我使用 QuantLib 和 Boost,但所有其他单元测试都可以正常工作

  • Same as previous link

提前致谢!

【问题讨论】:

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


    【解决方案1】:

    经过无数次努力解决问题,我终于做到了。这是因为我使用的是静态链接的 MKL,而我的程序是使用选项Property -> C/C++ -> Code Generation -> Runtime Library -> xxx DLL 编译的。

    希望对你有帮助!

    【讨论】:

    • 仅供参考,我对您的帖子进行了小幅编辑,以便撤消 10 天前意外投下的反对票。我可能在使用 Surface Pro 工作并在颠簸的火车回家途中轻扫了按钮。
    猜你喜欢
    • 1970-01-01
    • 2018-03-13
    • 2019-06-02
    • 2014-11-10
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    相关资源
    最近更新 更多