Visual Studio Team Suite has no Assert.AlmostEquals
Gah!
Say I am writing a unit test for a class that converts metres to feet. This, naturally, involves floats. Ideally my code looks like
float expected=32.91; // in feet
Distance dist = new Distance (10,”m”);
Assert.AlmostEquals(dist.convertToUnit(”ft”),expected);
where the “AlmostEquals” method does something smart like compares the first decimal place or so. I think JUnit/NUnit/etc actually allow you to spec a precision.
Microsoft haven’t managed this, so I have to write stuff like
float expected=32.91; // in feet
Distance dist = new Distance (10,”m”);
float difference = Math.abs(expected - dist.convertToUnit(ft)); // java ism, not sure of the .net Abs method offhand
Assert.IsTrue(difference<0.01);
Unit tests need to be as crystal clear in their intent and as quick to write as possible. Every little tiny rough edge will catch your project thousands of times over. So a big “bah” to Microsoft for this one.






Recent Comments