Stop test & mark as completed (during Test)

I'm looking for a way for CUI-Tests to stop a test through a command, however return that the test was completed successfully. For Example:

if (something)
{
   //Code
}
else
{
   //Test should be aborted here; but marked as Completed
}

Thanks in advance!

Upvotes: 0

Views: 52

Answers (1)

AdrianHHH
AdrianHHH

Reputation: 14038

One simple mechanism is to move the body of the test method into a helper method and have the main test method call that helper. Whenever the test needs to exit and have the test pass just do a return. The code would look something like the following:

[TestMethod]
public void CodedUITestMethod1()
{
    CodedUITestMethod1Helper();
}

public void CodedUITestMethod1Helper()
{
    ... some test code ...;

    if (something)
    {
       ... more test code ...;
    }
    else
    {
       // Test is aborted here; but marked as Completed
       return;
    }

    ... some test code ...;

    if (something else)
    {
       ... more test code ...;
    }
    else
    {
       // Test is aborted here; but marked as Completed
       return;
    }

    ... some test code ...;
}

Upvotes: 1

Related Questions