Skip to content

Instantly share code, notes, and snippets.

@0x49D1
Created February 3, 2020 07:26
Show Gist options
  • Save 0x49D1/c664781154b61c31cde344f232447f61 to your computer and use it in GitHub Desktop.
Save 0x49D1/c664781154b61c31cde344f232447f61 to your computer and use it in GitHub Desktop.
Ignore xUnit test when running tests not in DEBUG mode.
/// <summary>
/// Credits to https://lostechies.com/jimmybogard/2013/06/20/run-tests-explicitly-in-xunit-net/
/// </summary>
public class RunnableInDebugOnlyAttribute : FactAttribute
{
public RunnableInDebugOnlyAttribute()
{
if (!Debugger.IsAttached)
{
Skip = "Only running in interactive mode.";
}
}
}
//// After that just use the attribute `RunnableInDebugOnlyAttribute` instead of `Fact` when you want the test to be ignored in automatic runs without debug, for example
// Example of method in test suite
// [RunnableInDebugOnlyAttribute()]
// public void Test()
// {
// Runs only in debug mode
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment