Skipping Unit tests In MSTest

When creating a large number of test cases for a project there may be a number of cases that don’t apply for some particular scenario or platform. I didn’t want to mark a non-applicable test case as having passed just because it did not apply to the relevant platform and I certainly didn’t want to mark the test as having failed.

The meager MSTest documentation didn’t provide anything obvious that allowed me to ignore certain tests under some conditions. A quick Google search did turn up a simple solution though that worked perfectly. The Assert command can be used to mark the test as being not applicable.

if (!Helper.bSupportsDynamicTickets)
{
    Assert.Inconclusive("Not supported on this platform.");
    return;
}

Now, when the test is not pertinent it’s included in the TestExplorer’s “Skipped Tests” node.

This entry was posted in Programming and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.