I started working with xUnit
and I have a question.
Let's say I'm testing a function that receives an int
and returns true
if the parameter is greater than 10.
I know that I could do this:
[Theory]
[InlineData(7)]
[InlineData(13)]
[InlineData(4)]
public void MyTest(int num)
{
bool res = MyCompMethod(num);
Assert.True(res);
}
But it doesn't seem good enough because it will show that some of the tests have failed, although they didn't. I want to enter the expected result as well, so I could compare the values, something like:
[Theory]
[InlineData(7), false]
[InlineData(13), true]
[InlineData(4), false]
Is there something like that?
There isn't such attribute, but you could do this instead:
[Theory]
[InlineData(7, false)]
[InlineData(13, true)]
[InlineData(4, false)]
public void MyTest(int num, bool shouldBeGreaterThanTen)
{
bool isGreaterThanTen = MyCompMethod(num);
Assert.Equal(shouldBeGreaterThanTen, isGreaterThanTen);
}
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