If you want to enable or disable unit tests in Microsoft Visual Studio 2010, you can use the “Ignore” attribute.

This can be used to ignore ore exclude integration tests in a nightly continuous integration build.

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Rvl.Demo.Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        [Ignore]
        public void TestMethod1()
        {
            // This unit test will be excluded (ignored) from the test runs
        }
    }
}

One Comment

  1. Nice example.
    The only thing to add:

    E.g. you call a method in the test that doesn’t exist and use the [Ignore] there will still be a compiler error!
    It ignores the test while running them but it doesn’t ignore the test while compiling!

    Andreas

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.