【问题标题】:ExpectedException ignored by mstest v2 when running from the command line从命令行运行时 mstest v2 忽略 ExpectedException
【发布时间】:2017-03-29 11:09:56
【问题描述】:

我正在尝试使用新的“mstest v2”框架,但是在从命令行使用 mstest.exe 运行测试时遇到了问题。具体来说,ExpectedExceptionAttribute 和 DeploymentItemAttribute 不起作用。

这是我的示例测试:

[TestMethod]
[ExpectedException(typeof(NotImplementedException))]
public void ExpectedExceptionShouldWork()
{
    throw new NotImplementedException(
       "This exception should not cause the test to fail");
}

我很确定这是由从 Microsoft.VisualStudio.TestPlatform.TestFramework 程序集而不是来自 Microsoft.VisualStudio.QualityTools.UnitTestFramework - 然后 mstest.exe 无法识别它们。

我们在构建服务器 (Teamcity) 中运行 mstest.exe,但测试在那里失败,即使它们在 IDE 中成功。 Mstest.exe 在本地运行时也会失败

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\MSTest.exe" /testcontainer:bin\Debug\Dummy.Test.dll

当我的项目引用 Microsoft.VisualStudio.QualityTools.UnitTestFramework 时,它可以在命令行和 IDE 中运行。

如果我随后添加对 MSTest.TestFramework v 1.1.13 的 nuget 引用,则会收到编译错误:

Error   CS0433  
The type 'TestClassAttribute' exists in both 
'Microsoft.VisualStudio.QualityTools.UnitTestFramework, 
Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 
'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

然后,当我删除对 Microsoft.VisualStudio.QualityTools.UnitTestFramework 的引用时,它会在 IDE 中编译和工作 - 但不是从命令行。测试已运行,但由于抛出异常而失败。

我们真的很想使用 mstest v2 中的新东西,例如 [DataTestMethod],但我们不能让构建服务器上的构建失败。

有什么解决方法吗? 这不仅仅是关于 [ExpectedException]? [AssemblyInitialize] 等其他属性似乎也被忽略了?

【问题讨论】:

    标签: c# mstest


    【解决方案1】:

    请使用vstest.console.exe 运行在 MSTest v2 中编写的单元测试。

    mstest.exe 仅支持 mstest v1 测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 2015-01-15
      • 2011-05-30
      • 2010-10-18
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多