c++ - 如何在 Linux 中运行 visual studio 2015 managed c++ 测试函数?

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

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

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

对于普通的 c++ 程序我有 make 文件,我不知道如何在 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 环境很好)。

请帮帮我

最佳答案

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

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

关于c++ - 如何在 Linux 中运行 visual studio 2015 managed c++ 测试函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45117777/

相关文章:

java - 需要有效地实现以下公式吗?

linux - SSD的“典型”延迟意味着什么?

regex - 在 bash 脚本中查找文件夹名称的一部分

c# - 如果用户正在键入,则延迟 KeyUp 操作 (C#)

c# - 在 SSIS 中使用脚本任务设置变量值

c++ - 解析文本文件时抛出 std::out_of_range

c++ - 从 protected 嵌套类继承的公共(public)嵌套类?

2个矩阵的C++乘法

linux - 在 Linux 上从头开始创建线程

visual-studio - Visual Studio 2015 扩展管理器索引超出范围错误