To exclude tests from Live Unit Testing, you can simply right-click on the test file and select “Exclude” from the context menu.

After this, none of the tests in that file will be executed by Live Unit Testing. You can also exclude an entire project. So, if you organize unit tests and integration tests into separate projects, then you are all set.

If you don’t organize them into separate projects, then this process could be a bit tedious. Further, the Include/Exclude information is a local setting that can’t (as of the time I’m writing this, and to the best of my knowledge) be committed to source control.

So, after asking about Live Testing exclusion on StackOverflow, I created an attribute that you can place on tests to exclude them from Live Testing.

public class IgnoreForLiveTesting : Attribute, ITestAction { readonly string _ignoreReason; public IgnoreForLiveTesting(string ignoreReason = null) { _ignoreReason = ignoreReason; } public ActionTargets Targets { get; set; } public void AfterTest(ITest test) { } public void BeforeTest(ITest test) { var isLiveTesting = AppDomain.CurrentDomain.GetAssemblies() .Any(a => a.GetName().Name == "Microsoft.CodeAnalysis.LiveUnitTesting.Runtime"); if (isLiveTesting) Assert.Ignore(_ignoreReason ?? "Ignoring this test"); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class IgnoreForLiveTesting : Attribute , ITestAction { readonly string _ignoreReason ; public IgnoreForLiveTesting ( string ignoreReason = null ) { _ignoreReason = ignoreReason ; } public ActionTargets Targets { get ; set ; } public void AfterTest ( ITest test ) { } public void BeforeTest ( ITest test ) { var isLiveTesting = AppDomain . CurrentDomain . GetAssemblies ( ) . Any ( a = > a . GetName ( ) . Name == "Microsoft.CodeAnalysis.LiveUnitTesting.Runtime" ) ; if ( isLiveTesting ) Assert . Ignore ( _ignoreReason ? ? "Ignoring this test" ) ; } }

This attribute implements the ITestAction interface (which is kinda like Aspect-Oriented Programming/AOP for NUnit, but that’s a topic for a whole other blog post). It will check to see if it’s being run by a LiveUnitTesting process. If it is, it instructs NUnit to ignore the test.

Furthermore, I added an optional ignoreReason to the constructor, so that you can add a helpful note to other people on your team to explain why this test should not be run with Live Unit Testing. You can use it on an integration test like so: