Skip to main content

Skipping Tests

If you want to simply skip a test, just place a [Skip(reason)] attribute on your test with an explanation of why you're skipping it.

using TUnit.Core;

namespace MyTestProject;

public class MyTestClass
{
[Test, Skip("There's a bug! See issue #1")]
public async Task MyTest()
{
...
}
}

Custom Logic​

The SkipAttribute can be inherited and custom logic plugged into it, so it only skips the test if it meets certain criteria.

As an example, this could be used to skip tests on certain operating systems.

public class WindowsOnlyAttribute() : SkipAttribute("This test is only supported on Windows")
{
public override Task<bool> ShouldSkip(TestRegisteredContext context)
{
return Task.FromResult(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
}
}
using TUnit.Core;

namespace MyTestProject;

public class MyTestClass
{
[Test, WindowsOnly]
public async Task MyTest()
{
...
}
}

Global Skipping​

In case you want to skip all tests in a project, you can add the attribute on the assembly level.

[assembly: Skip("Skipping all tests in this assembly")]

Or you can skip all the tests in a class like this:

[Skip("Skipping all tests in this class")]
public class MyTestClass
{
}