Is it possible to specify the return value for a theory case? Like I have the test methode:
[Theory]
[MemberData(nameof(TestCases))]
public async Task<bool> Test(int i, double d, string str)
{
return DoStuffAsync(i, d, str);
}
and the methode
public static IEnumerable<object[]> TestCases()
{
yield return new object[] { 1, Math.PI, "case1", true };
yield return new object[] { 2, Math.E, "case2", false };
}
to produce the test cases.
But if I try to run these test cases, I get the error
System.InvalidOperationException : The test method expected 3 parameter values, but 4 parameter values were provided.
You can rewrite your test a little bit, by adding the parameter for expected result and compare it in Assert
with value, returned from DoStuffAsync
method. Also don't forget to change the return value for test method from Task<bool>
to just Task
or async void
, since you are checking the return value inside test and return nothing
[Theory]
[MemberData(nameof(TestCases))]
public async Task Test(int i, double d, string str, bool expected)
{
var result = await DoStuffAsync(i, d, str);
Assert.Equal(expected, result);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With