我正在尝试使用新的"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");
}
Run Code Online (Sandbox Code Playgroud)
我很确定它是由从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
Run Code Online (Sandbox Code Playgroud)
当我的项目引用Microsoft.VisualStudio.QualityTools.UnitTestFramework时,它可以在命令行和IDE中工作.
如果我然后添加一个nuget引用到MSTest.TestFramework v 1.1.13,我得到一个编译错误:
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'
Run Code Online (Sandbox Code Playgroud)
当我删除对Microsoft.VisualStudio.QualityTools.UnitTestFramework的引用时,它在IDE中编译并工作 - 但不是从命令行.测试已运行,但由于抛出异常而失败.
我们真的想使用来自mstest v2的新东西,比如[DataTestMethod],但是我们不能在构建服务器上使构建失败.
有没有解决方法?它不只是关于[ExpectedException]?其他属性如[AssemblyInitialize]似乎也被忽略了?