Are there any means in xUnit.net framework similar to the following features of NUnit?
[Test, TestCaseSource("CurrencySamples")]
public void Format_Currency(decimal value, string expected){}
static object[][] CurrencySamples = new object[][]
{
new object[]{ 0m, "0,00"},
new object[]{ 0.0004m, "0,00"},
new object[]{ 5m, "5,00"},
new object[]{ 5.1m, "5,10"},
new object[]{ 5.12m, "5,12"},
new object[]{ 5.1234m, "5,12"},
new object[]{ 5.1250m, "5,13"}, // round
new object[]{ 5.1299m, "5,13"}, // round
}
This will generate 8 separate tests in NUnit GUI
[TestCase((string)null, Result = "1")]
[TestCase("", Result = "1")]
[TestCase(" ", Result = "1")]
[TestCase("1", Result = "2")]
[TestCase(" 1 ", Result = "2")]
public string IncrementDocNumber(string lastNum) { return "some"; }
This will generate 5 separate tests and automatically compare the results (Assert.Equal()
).
[Test]
public void StateTest(
[Values(1, 10)]
int input,
[Values(State.Initial, State.Rejected, State.Stopped)]
DocumentType docType
){}
This will generate 6 combinatorial tests. Priceless.
Few years ago I tried xUnit and loved it but it lacked these features. Can't live without them. Has something changed?
See Question&Answers more detail:
os