[英]ExpectedException ignored by mstest v2 when running from the command line
我正在尝试使用新的“ 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]似乎也被忽略了吗?
请使用vstest.console.exe
运行MSTest v2中编写的单元测试。
mstest.exe
仅支持mstest v1测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.