0
[重複的] Assert in Try..Catch block is caughtxUnit的核心是不工作的權利
當我使用的xUnit核心在NetCore1.1在VS2017爲folllow:
try
{
Assert.True(1<0," server is false");//vs2017 show green(test through)
}
catch (Exception e)
{
while (e != null)
{
_outputHelper.WriteLine(e.Message);
e = e.InnerException;
}
}
Assert.True(1 < 0, "current value is false");// vs2017 show red(test failed
結果圖標是綠色的,不是紅色的時候第一個Assert.True
不對(失敗)。如下圖:
如果加上第二個Assert.True
它是紅色的;
這是非常奇怪的,是嗎?我認爲這是一個錯誤。
Hi @Brad Wilson,謝謝你的回覆?我想測試EF演示功能,[這裏](https://github.com/huoxudong125/HQF.Tutorials.EntityFrameworkCore/blob/master/Tests/HQF.Tutorials.EntityFrameworkCore.XUnitTest/UnitTest1.cs)是完整的演示碼。有沒有一個好的模式來實現? – huoxudong125
只是不抓。任何拋出的異常都將顯示爲失敗。你可以離開try/finally進行資源清理,只是沒有捕獲。 –