一旦特定的断言通过,如何跳过Nunit测试用例中的进一步执行

时间:2014-09-08 11:03:10

标签: unit-testing nunit nunit-2.5 nunit-console nunit-2.5.9

以下是我的测试用例,

Public static void SampleTest() 
{
    // Pre conditions for both assert 1 and 2
    if(condition1)
    {
        // Assert 1
    }
    // Pre condition for Assert 2
    // Assert 2
}

一旦condition1满足并且断言1执行,我不想在上面的测试用例中执行进一步的语句。另一方面,如果condition1失败,它应该执行assert 2的前提条件,并且应该根据assert 2发布结果

提前致谢。

1 个答案:

答案 0 :(得分:1)

您只需在return;之后致电Assert 1

Public static void SampleTest() 
{
    // Pre conditions for both assert 1 and 2
    if(condition1)
    {
        // Assert 1
        return;
    }
    // Pre condition for Assert 2
    // Assert 2
}
相关问题