[英]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.