This new functionality enables you to specify a tabular list of test cases that are to be feeded to the test method. It can be illustrated with the floating point division testing (as in the FIT framework Simple Example ):
numerator | denominator | quotient() |
1000 | 10 | 100.0000 |
-1000 | 10 | -100.0000 |
1000 | 7 | 142.85715 |
1000 | .00001 | 100000000 |
4195835 | 3145729 | 1.3338196 |
You can now translate this directly to C# in MbUnit using the RowTestAttribute and the RowAttribute:
[TestFixture] public class DivisionFixture { [RowTest] [Row(1000,10,100.0000)] [Row(-1000,10,-100.0000)] [Row(1000,7,142.85715)] [Row(1000,0.00001,100000000)] [Row(4195835,3145729,1.3338196)] public void DivTest(double numerator, double denominator, double result) { Assert.AreEqual(result, numerator / denominator, 0.00001 ); } }
Of course, these tests are not very well targeted because we do not test the “special” floating point values such as 1,0,double.MaxValue, double.MinValue, NaN but you get the picture.
What if a test should throw ? In that case, you can specify the exception type as an additional parameter in the RowAttribute constructor:
[Row(1,0,0, ExpectedException = typeof(ArithmeticException))] public void DivTest(double numerator, double denominator, double result) {...}
The final output of the tests is as follows where you can see that 5 tests (one per row) were generated and executed.
Info: Found 5 tests Info: [assembly-setup] success Info: [success] RowTestDemo.DivTest(0) Info: [success] RowTestDemo.DivTest(1) Info: [success] RowTestDemo.DivTest(2) Info: [success] RowTestDemo.DivTest(3) Info: [success] RowTestDemo.DivTest(4) Info: [assembly-teardown] success Info: [reports] generating HTML report
Leave a Reply
You must be logged in to post a comment.