Created
January 27, 2014 08:36
-
-
Save robdmoore/8644975 to your computer and use it in GitHub Desktop.
Data-driven tests with NUnit and XUnit when you have a Specification base class
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
public abstract class Specification | |
{ | |
[Test] | |
public virtual void Run() | |
{ | |
this.BDDfy(); | |
} | |
[Fact] | |
public void RunX() | |
{ | |
this.BDDfy(); | |
} | |
} | |
public class NormalSpec : Specification | |
{ | |
public void GivenX() | |
{ | |
} | |
public void WhenY() | |
{ | |
} | |
public void ThenZ() | |
{ | |
} | |
} | |
public class DataDrivenSpec : Specification | |
{ | |
private int _x; | |
[Ignore] | |
public override void Run() {} | |
public new void RunX() {} | |
public void GivenX() | |
{ | |
} | |
public void WhenY() | |
{ | |
Console.WriteLine(_x); | |
} | |
public void ThenZ() | |
{ | |
} | |
[Test] | |
[TestCase(1)] | |
[TestCase(2)] | |
public void RunSpec(int x) | |
{ | |
_x = x; | |
base.Run(); | |
} | |
[Xunit.Extensions.Theory] | |
[InlineData(1)] | |
[InlineData(2)] | |
public void RunSpecX(int x) | |
{ | |
_x = x; | |
base.RunX(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is very handy. Thanks for sharing.