UvarajGopu
UvarajGopu

Reputation: 27

How to skip further execution in Nunit test case once particular assert passes

Below is my test case,

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

Once condition1 satisfied and assert 1 executes I don't want to execute the further statements in above test case. On the other hand, if condition1 fails it should execute precondition for assert 2 and should publish the result based on assert 2

Thanks in advance.

Upvotes: 0

Views: 350

Answers (1)

hunch_hunch
hunch_hunch

Reputation: 2331

You can simply call return; after 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
}

Upvotes: 1

Related Questions