Per
Per

Reputation: 1425

How do I avoid to run tests in mstest not using ignore attribute?

We have a couple of unit tests that we use when integrating with external services. These services can be unstable and they are out of our control which makes it necessary to remove them from our daily build.

We have integration tests in a separate assembly already since the usual unit tests are run as part of our gated checkin.

Though, there are still a number of integration tests we wish to be run as part of our daily build and therefore we cannot remove the assemblies completely from the daily build.

I tried to remove the [TestClass] attribute and that works fine inside VS2012. But when we checkin and have TFS (2010) to build and run the tests I got the below error.

[errormessage] = UTA004: Illegal use of attribute on Test.TestMethod. The TestMethodAttribute can be defined only inside a class marked with the TestClass attribute.

Anyone having an idea how to completely remove the test runs? [Ignore] will not do, then my test runs will be cluttered with warnings about ignored tests.

Upvotes: 4

Views: 2497

Answers (1)

DaveShaw
DaveShaw

Reputation: 52798

Why not use the TestCategoryAttribute to decorate your integration tests.

For example make your tests like this:

[TestClass]
public class Tests
{
    [TestMethod]
    public void AtomicTest
    {
        Assert.IsTrue(true);
    }

    [TestMethod, TestCategory("Integration")]
    public void IntegrationTest
    {
        Assert.IsFalse(false);
    }
}

And then configure your TFS builds to only run the ones you are interested in:

Upvotes: 6

Related Questions