简体   繁体   English

从命令行运行时,mstest v2会忽略ExpectedException

[英]ExpectedException ignored by mstest v2 when running from the command line

I am trying to use the new "mstest v2" framework, but are running into problems when running tests with mstest.exe from the command line. 我正在尝试使用新的“ mstest v2”框架,但是从命令行使用mstest.exe运行测试时遇到了问题。 Specifically, ExpectedExceptionAttribute and DeploymentItemAttribute are not working. 具体来说,ExpectedExceptionAttribute和DeploymentItemAttribute不起作用。

Here is my sample test: 这是我的示例测试:

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

I am pretty sure it is caused by the attributes being picked up from the Microsoft.VisualStudio.TestPlatform.TestFramework assembly instead of from Microsoft.VisualStudio.QualityTools.UnitTestFramework - then mstest.exe doesn't recognize them. 我很确定这是由从Microsoft.VisualStudio.TestPlatform.TestFramework程序集而不是从Microsoft.VisualStudio.QualityTools.UnitTestFramework拾取的属性引起的,然后mstest.exe无法识别它们。

We run mstest.exe in our build server (Teamcity) and tests fail there, even though they succeed in the IDE. 我们在构建服务器(Teamcity)中运行mstest.exe,即使在IDE中成功,测试也在那里失败。 Mstest.exe also fails when running them locally with 使用以下命令在本地运行Mstest.exe时也会失败

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

When my project references Microsoft.VisualStudio.QualityTools.UnitTestFramework, it works on the command line and in the IDE. 当我的项目引用Microsoft.VisualStudio.QualityTools.UnitTestFramework时,它将在命令行和IDE中工作。

If I then add a nuget reference to MSTest.TestFramework v 1.1.13, I get a compile error: 如果然后添加对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'

When I then remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework, it compiles and works in the IDE - but not from the command line. 然后,当我删除对Microsoft.VisualStudio.QualityTools.UnitTestFramework的引用时,它将在IDE中编译并运行-但不能从命令行运行。 The test is run, but fails due to the exception being thrown. 测试已运行,但由于引发异常而失败。

We would really like to use new stuff from mstest v2 such as [DataTestMethod], but we cannot have builds failing on the build server. 我们确实很想使用mstest v2中的新内容,例如[DataTestMethod],但是我们不能在构建服务器上使构建失败。

Are there any workarounds? 有什么解决方法吗? It's not just about [ExpectedException]? 不只是[ExpectedException]? Other attributes such as [AssemblyInitialize] seems to be ignored as well? 其他属性,例如[AssemblyInitialize]似乎也被忽略了吗?

Please use vstest.console.exe to run the unit tests authored in MSTest v2. 请使用vstest.console.exe运行MSTest v2中编写的单元测试。

mstest.exe only supports the mstest v1 tests. mstest.exe仅支持mstest v1测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM