C
C#4mo ago
Jasonnn

✅ 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
Jasonnn
JasonnnOP4mo ago
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?
333fred
333fred4mo ago
What is the actual signature of GetNumber?
Jasonnn
JasonnnOP4mo ago
public int? GetNumber(int row, int column)
333fred
333fred4mo ago
Then yes, use Assert.Null
Jasonnn
JasonnnOP4mo ago
Ok so I definitely got scared because my IDE took time to refresh the warnings thanks for confirming!
333fred
333fred4mo ago
Don't forget to $close the thread if that's it 🙂
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server