Say I have a method :
public void Foo(double bar, double bar2, double bar3, double bar4)
{
if (bar.IsNaNOrInfinity()) throw new ArgumentOutOfRangeException();
// x4
}
What is the best practice for writing a unit test for this? Do I write a test that checks NaN, +Infinity and -Infinity for EVERY SINGLE double param? Imagine I had 4 doubles, like for some sort of rectangle, that would mean 12 tests just for testing NaN's and Infinity...
Test_Foo1_NaN_ThrowsException ()
Test_Foo1_PosInfinity_ThrowsException ()
Test_Foo1_NegInfinity_ThrowsException ()
...
Is there any guideline for this?
Current approach is to write many tests like this:
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Foo1_WithNaN_ShouldThrowArgumentOutOfRangeException()
{
new Foo(double.NaN, 0, 0, 0);
}
Aucun commentaire:
Enregistrer un commentaire