Esistono mezzi nel framework xUnit.net simili alle seguenti funzionalità di NUnit?Parametrizzazione del test in xUnit.net simile a 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
}
Questo genererà 8 prove separate 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"; }
Questo genererà 5 prove distinte e confronta i risultati automaticamente (Assert.Equal()
).
[Test]
public void StateTest(
[Values(1, 10)]
int input,
[Values(State.Initial, State.Rejected, State.Stopped)]
DocumentType docType
){}
Questo genererà 6 test combinatori. Inestimabile.
Pochi anni fa ho provato xUnit e l'ho adorato ma mancava di queste funzionalità. Non posso vivere senza di loro. Qualcosa è cambiato?
a quanto pare, è [non consentito] (http://stackoverflow.com/questions/507528/use -decimal-values-as-attribute-params-in-c) da utilizzare valori letterali decimali come parametri degli attributi. –
@RubenBartelink il tuo link non è stato trovato. Vai qui invece: http://blog.benhall.me.uk/2008/01/introduction-to-xunit-net-extensions/ –
Avrai bisogno di _xUnit.net: Extensions_ (pacchetto NuGet) o altrimenti il '[ L'attributo teoria] 'non è disponibile. – Virtlink