Status of Data Driven tests
"Charlie Poole" <[email protected]> Tue, 25 Mar 2008 13:24:05 -0700
| Newsgroups | gmane.comp.windows.dotnet.nunit.devel |
|---|---|
| Message-ID | <016501c88eb6$2ce24ec0$6401a8c0@ferrari> |
I'm resending this, since it didn't seem to be accepted the first time.
Hi All,
I have a basic skeleton for static test data applied
to methods in the manner of RowTest.
These work...
[TestCase(2, 2, 4)]
public void TestMethod(int a, int b, int sum)
{
Assert.AreEqual( sum, a + b );
}
[TestCase(2, 2, 4)]
[TestCase(10, 1, 11)]
[TestCase(2, -2, 0)]
public void TestMethod(int a, int b, int sum)
{
Assert.AreEqual( sum, a + b );
}
In the first example, the test is shown right under the fixture.
In the second, a group is created, with the tests under it
just as in RowTest.
A few differences in my implementation...
* Mismatched args are non-runnable rather than throwing
an exception at runtime.
* It works on static methods as well as instance methods
I haven't yet implemented ExpectedException, TestName
or Description, but they seem straightforward enough.
Do we need/want all these?
I'll add use of a property or method to return argument
lists in the fashion of IterativeTest.
I'm considering allowing methods with return values, with
the test cases specifying the expected value and NUnit
doing an automatic assertion on equality.
[TestCase(2, 2, Expect=4)]
[TestCase(10, 1, Expect=11)]
[TestCase(2, -2, Expect=0)]
public int TestMethod()
{
return MyAddMethod(a, b);
}
This would allow something very close to testing
the production code directly. Does it look like
it might be useful?
Charlie
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/