Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an expected result attribute in xUnit?

Tags:

c#

xunit.net

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?

like image 803
GM6 Avatar asked Apr 16 '15 13:04

GM6


1 Answers

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);
}
like image 176
dcastro Avatar answered Sep 19 '22 17:09

dcastro