2
我想忽略某些測試,這些測試是基於我在TestFixtureSetUp
期間從配置文件中提取的數據。有沒有辦法忽略基於參數運行測試?選擇性忽略NUnit測試
[TestFixture]
public class MessagesTests
{
private bool isPaidAccount;
[TestFixtureSetUp]
public void Init() {
isPaidAccount = ConfigurationManager.AppSettings["IsPaidAccount"] == "True";
}
[Test]
//this test should run only if `isPaidAccount` is true
public void Message_Without_Template_Is_Sent()
{
//this tests an actual web api call.
}
}
如果我們測試的帳戶是付費帳戶,測試應該正常運行,否則該方法會拋出異常。
是否會有擴展屬性[Ignore(ReallyIgnore = isPaidAccount)]
?或者我應該在方法中寫入這些內容,併爲例如2個單獨的測試用例運行。
public void Message_Without_Template_Is_Sent()
{
if(isPaidAccount)
{
//test for return value here
}
else
{
//test for exception here
}
}
好問題。 +1 –
'Assert.Ignore()'在測試中。 – Matthew
@Matthew所以它很好的做法,只是檢查條件之前,忽略測試? –