Last active
August 29, 2015 14:10
-
-
Save robfe/d5f9cc160dcb573bd7ea to your computer and use it in GitHub Desktop.
Make XUnit tests dynamically skippable for SpecLight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Speclight users like to see "Pending" steps (that throw NotImplementedException) as "skip" not "fail" | |
/// </summary> | |
public class SpecAttribute : FactAttribute | |
{ | |
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method) | |
{ | |
yield return new SkipIfNotImplemented(method); | |
} | |
class SkipIfNotImplemented : FactCommand | |
{ | |
public SkipIfNotImplemented(IMethodInfo method) : base(method){} | |
public override MethodResult Execute(object testClass) | |
{ | |
try | |
{ | |
return base.Execute(testClass); | |
} | |
catch (NotImplementedException e) | |
{ | |
return new SkipResult(testMethod, DisplayName, e.Message); | |
} | |
} | |
} | |
//the rest of this file can be deleted if you're not using ApprovalTests.Net | |
static SpecAttribute() | |
{ | |
ApprovalTests.Namers.StackTraceParsers.StackTraceParser.AddParser(new StackTraceParser()); | |
} | |
public class StackTraceParser : AttributeStackTraceParser | |
{ | |
public override string ForTestingFramework | |
{ | |
get { return "xUnit Spec"; } | |
} | |
protected override string GetAttributeType() | |
{ | |
return typeof(SpecAttribute).FullName; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment