✅ Nullable<int> and xUnit
I'm writing unit tests for a method that has
int?
as a return type.
When I do:
Assert.Equal(null, parser.GetNumber(myArguments));
xUnit tells me
xUnit2003: Do not use Assert. Equal() to check for null value. Use Assert.Null instead.
When I do
Assert.Null(parser.GetNumber(myArguments));
It tells me
xUnit2002: Do not use Assert.Null() on value type 'int'. Remove this assert.
What is happening? What should I do?7 Replies
Actually the second was just my IDE that didn't see that I had replaced
int
by int?
I think, the warning just disappeared. My bad.
Should I use Assert.Null()
even though the XML doc says "object" and I'm technically using it on a value type? Maybe it just boxes my value type automatically?What is the actual signature of
GetNumber
?public int? GetNumber(int row, int column)
Then yes, use
Assert.Null
Ok so I definitely got scared because my IDE took time to refresh the warnings
thanks for confirming!
Don't forget to $close the thread if that's it 🙂
If you have no further questions, please use /close to mark the forum thread as answered