Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 Live Testing exclusions

I'm looking at Live Testing feature in the new Visual Studio (I'm using NUnit).

There is an "exclude" option for unit tests, to indicate that specific tests should not be run (maybe they are integration tests, or slow tests, or whatever).

enter image description here

Where does this information get stored? I don't see any indication in the csproj or anywhere else that a test should not be included in Live Testing. Shouldn't there be some information file somewhere that I can check into source control so the rest of my team doesn't have to manually specify which tests should not be run by live testing?

like image 833
Matthew Groves Avatar asked Feb 05 '23 22:02

Matthew Groves


2 Answers

Include/exclude is a user level feature. This is extremely useful when you want to run a specific set of tests for a particular edit session or to persist your own personal preferences. To prevent tests from running and to persist that information, you could do something like the following:

[ExcludeFromCodeCoverage]
public class SkipLiveFactAttribute : FactAttribute
{
    private static bool s_lutRuntimeLoaded = AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == "Microsoft.CodeAnalysis.LiveUnitTesting.Runtime");

    public override string Skip => s_lutRuntimeLoaded ? "Test excluded from Live Unit Testing" : "";
}

public class Class1
{
    [SkipLiveFact]
    public void F()
    {
        Assert.True(true);
    }
}
like image 68
Manish Jayaswal Avatar answered Feb 07 '23 13:02

Manish Jayaswal


You can now use the following attributes to specify in source code that you want to exclude targeted test methods from Live Unit Testing:

For xUnit: [Trait("Category", "SkipWhenLiveUnitTesting")]
For NUnit: [Category("SkipWhenLiveUnitTesting")]
For MSTest: [TestCategory("SkipWhenLiveUnitTesting")]

Offical Docs here

like image 36
ilkerkaran Avatar answered Feb 07 '23 12:02

ilkerkaran