Arsen Magomedov
Arsen Magomedov

Reputation: 480

How to force unit test's state to "Test wasn't run"? (MS Test)

I have a few unit tests that are testing a proxy for 3-rd party REST API (GET only). The data that this API returns can change and sometimes there is no data at all. That means that sometimes, i can't check whether my code works, or not. I don't want to make my tests pass when they haven't checked everything, and i also don't want it to fail everytime there is no data. I'm using Ms Test, and I've noticed, that there is "Test wasn't run" state of the tests, which is assigned to tests in some situations. Can i call this state explicitly from my unit tests code, or this is a bad idea and theres a well known practice for this kind of situations?

Upvotes: 1

Views: 285

Answers (2)

Jeff Prince
Jeff Prince

Reputation: 678

What you should do when you determine that you have no results to test is call Assert.Inconclusive(). The Test Explorer will display the result as such and you can also provide a descriptive string to indicate what has happened.

For example:

[Test}
public void TestGetResults()
{
    .. do GET operation
    if (getfailed)
    {
        Assert.Inconclusive("Unable to get data for test.";
        return;
    }
}

Upvotes: 2

Robbie Dee
Robbie Dee

Reputation: 1977

Look at the TestCategory attribute. For all tests which may fail due to upstream layers, we mark these as Integration. You can then filter the tests by trait in the test explorer.

[TestMethod, TestCategory("Integration")]
public void MyTest()

Upvotes: 2

Related Questions