IgnoreException
,因此不会触发Nunit。这并不理想,因为我有每个测试案例之后要执行的代码。
在理想的世界中,我希望我可以在忽略 /跳过的一部分中设置测试结果,例如:
TearDown
else
{
//it's after the 25th of the month let's skip this test case
TestContext.CurrentContext.Result.Outcome == ResultState.Ignored;
}
只是一个有充分理由的是一个TestContext.CurrentContext.Result.Outcome
,很可能只会在人们不应该在不应该的时候通过的测试打开一罐蠕虫。
Get
[Test]
[TestCase(TestName = "Test A")]
[Description("Test A will be testing something.")]
[Category("Regression Test Pack")]
public void Test_Case_1()
{
sessionVariables = new Session().SetupSession(uiTestCase: true);
if (DateTime.Now.Day <= 25)
{
//let's test something!
}
else
{
//it's after the 25th of the month let's skip this test case
Assert.Ignore();
}
}
[TearDown]
public void Cleanup()
{
sessionVariables.TeardownLogic(sessionVariables);
}
不会导致跳过拆卸。 (如果确实如此,那将是一个尼古尼特错误,因为如果运行设置,必须始终运行拆卸)
因此,您选择如何结束测试取决于您希望如何显示结果...
返回的返回会导致测试通过,而没有任何特殊消息。
Assert.Ignore
做同样的事情,但允许您包括一条消息。
Assert.Pass
发出“忽略”警告,允许您指定原因。警告被传播,因此整个运行的结果也被“警告”。
Assert.Ignore
Assert.Inconclusive
的替代方案,您可以在适当的测试中使用
Assert.Inconclusive
。例如,以下代码将在本月25日之后触发“不确定的结果”:
Assume.That
Assume.That(DateTime.Now.Day <= 25);
Assume.That
方法的开始,在任何其他代码之前。
您可以只是SetUp
return
我遇到了同样的情况,我不希望测试报告说通过该特定测试的失败通行证。我尝试了
public void Test_Case_1()
{
sessionVariables = new Session().SetupSession(uiTestCase: true);
if (DateTime.Now.Day <= 25)
{
//let's test something!
}
else
{
//it's after the 25th of the month let's skip this test case
return;
}
}
,这有助于我确定未执行的测试。
@https://stackoverflow.com/users/3324415/bernardv