【问题标题】:How to run visual studio 2015 managed c++ test functions in Linux?如何在 Linux 中运行 Visual Studio 2015 托管 C++ 测试功能?
【发布时间】:2017-07-15 11:42:11
【问题描述】:

我已管理 VisualStudio 2015 C++ 程序的测试项目,

它工作正常,但我想在 Linux 环境中运行相同的测试用例,

对于我制作文件的普通 c++ 程序,我不知道如何在 Linux 中运行 Visual Studio 2015 托管 c++ 测试项目, 这是我的示例程序..

sample.h


#ifndef GUARD_SAMPLE
#define GUARD_SAMPLE
void method1();
void method2();
void method3();

而我的 c++ 程序是 sample.cpp

  #include "sample.h"

  void method1()
{
  int a,b=20,c=30;
  a=b+c;
  cout<<"sum is"<<a;
}

void method2()
{
  int a,b=20,c=30;
  a=b-c;
  cout<<"sub is"<<a;
}

void method3()
{
  int a,b=20,c=30;
  a=b*c;
  cout<<"mul is"<<a;
}

而我的测试程序是sample_Test.cpp

 #include "sample.h"

  namespace sample_MDM_Test
{
[TestClass]
public ref class sample_Testing
{
public: 
    [TestMethod]
    void Test_method1()
    {
        ::method1();
    }

    [TestMethod]
    void Test_method2()
    {
     ::method2();
    }

    [TestMethod]
    void Test_method3()
    {
     ::method3();
    }

我可以使用make file运行c++应用程序,但是如何在Linux环境下运行这些单元测试功能(对于windows环境就可以了)。

请帮帮我。

【问题讨论】:

  • AFAIK 托管和原生 VS C++ 单元测试都不能在非 Windows 系统上工作。就我个人而言,我想在任何地方都使用原生 VS C++ 单元测试,因为它们不像其他测试框架那样受到宏观影响,但是我不得不坚持使用 boost 测试。
  • @VTT:有没有办法在 Linux 环境中运行托管单元案例??给我任何建议。
  • 正如我在第一条评论中所写,似乎没有办法在 Linux 上运行它们。

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


【解决方案1】:

由于 sample_Test.cpp 不是 c++ 而是 c++/cli,因此您不能在 linux 环境中本机运行它。更多信息请看这里Does Mono .NET support and compile C++ / CLI?

如果您只需要原生 c++,请查看 gtest/gmock 作为测试框架。这将在 Windows 和 Linux 上运行,并且有一个集成到 VS2015 中的测试适配器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    相关资源
    最近更新 更多