Re: Data-driven Tests in NUnit 2.5

Andreas Schlapsi <[email protected]> Tue, 18 Mar 2008 00:49:45 +0100
Newsgroups gmane.comp.windows.dotnet.nunit.devel
Message-ID <1205797785.5708.21.camel@olorun>
Hi Charlie,

Am Sonntag, dem 16.03.2008, 18:02 -0700 schrieb Charlie Poole:
> Internally, NUnit will support an extension point
> for providing data to tests. The extension will
> return one of two things to NUnit:
> 
> 1) An actual data source, if the data is static.
> 2) An object for use at runtime to get the actual
>    data source, if the data is dynamic.

Will there be two separate extension points or just one?


> For static test methods, I'm thinking of supporting
> the following natively:
> 
> [TestFixture]
> public class StaticDataSample
> {
> 	 [TestCase( 1000, 10, 100.0000)]
> 	 [TestCase(-1000, 10, -100.0000)]
> 	 [TestCase( 1000, 7, 142.85715)]
> 	 [TestCase( 1000, 0.00001, 100000000)]
> 	 [TestCase(4195835, 3145729, 1.3338196)]
> 	 public void DivisionTest(double numerator, double denominator,
> double result)
> 	 {
> 	 	Assert.AreEqual(result, numerator / denominator, 0.00001);
> 	 }
> }
> 
> If you're familiar with RowTest, you'll see that this is
> essentially the same thing, with TestCase substituted for Row.
> In fact I took the example from Andreas and I think we can
> incorporate his code right into NUnit.

I'll help you with this.


> For dynamic data, I'm thinking of supporting something
> like this...
> 
> [TestFixture]
> public class DynamicDataSample
> {
> 	 [Test, DataSource( typeof(MyDataSource)]
> 	 public void DivisionTest(double numerator, double denominator,
> double result)
> 	 {
> 	 	Assert.AreEqual(result, numerator / denominator, 0.00001);
> 	 }
> }
> 
> Where MyDataSource is a class provided by the user. I'm
> still working on the details of this, so please throw in
> your ideas. I'd like to have a typesafe interface for
> data, rather than using a string.

This looks interesting. How would the typesafe interface look like? Will
an extension be able to provide another way of generating dynamic data
by using the extension point? Otherwise we won't need the extension
point for dynamic data (or to cope with the one returning an object
which returns the data at runtime), because the data source is specified
as type.


Andreas



-------------------------------------------------------------------------
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/