【问题标题】:MSTest V2 with x86 and x64MSTest V2 与 x86 和 x64
【发布时间】:2018-04-29 02:46:56
【问题描述】:

我有单元测试要求它们专门作为 x86 和 x64 运行。我遇到的问题是我无法运行所有单元测试,因为我必须从“测试”菜单切换框架。有没有更好的方法以更自动化的方式做到这一点? 理想情况下,我可以使用一个属性来指定测试是专门针对 x86 还是 x64。这是我的代码示例:

[TestMethod]
public void Testx86_Success()
{
    if (!Environment.Is64BitProcess)
    {
        //Arrange
        ...

        //Act
        ...

        //Assert
        Assert.IsTrue(true);
    }
    else
    {
        Assert.Inconclusive("Can't test x64 while running in x86 process.");
    }
}

[TestMethod]
public void Testx64_Success()
{
    if (Environment.Is64BitProcess)
    {
        //Arrange
        ...

        //Act
        ...

        //Assert
        Assert.IsTrue(true);
    }
    else
    {
        Assert.Inconclusive("Can't test x86 while running in x64 process.");
    }
}

【问题讨论】:

    标签: c# .net visual-studio unit-testing mstest


    【解决方案1】:

    你可以声明conditional compilation变量并使用它

    #if comp_x64
    [TestMethod]
    public void Testx64_Success()
    {
        if (Environment.Is64BitProcess)
        {
            //Arrange
            ...
    
            //Act
            ...
    
            //Assert
            Assert.IsTrue(true);
        }
        else
        {
            Assert.Inconclusive("Can't test x86 while running in x64 process.");
        }
    }
    #else
       . . . . your x86 test 
    #endif
    

    【讨论】:

    • 我没有尝试过,但我假设这会将它们从要测试的列表中删除。我不想忘记他们。感谢您提供此选项,但我认为我更喜欢当前的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2012-05-06
    • 2011-12-03
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多