Re: Data-driven Tests in NUnit 2.5

"Charlie Poole" <[email protected]> Wed, 19 Mar 2008 07:33:40 -0700
Newsgroups gmane.comp.windows.dotnet.nunit.devel
Message-ID <000001c889ce$41301e80$6701a8c0@ferrari>
Hi Andreas, 

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

I think we need one if some future extensions are going to support
both types of data, as shown by some of the Theory examples. I think
such extensions would have to treat all the  data dynamically for
consistency however.

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

Great. Lets get our heads together offline.

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

I'm not sure about the interface but I thought I'd throw the idea
out to let others think about it as well. I'll work on an example.

I think the extension would simply implement the interface - how
it created the  data would be an internal matter.

Charlie

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