Re: Data-driven Tests in NUnit 2.5

"Charlie Poole" <[email protected]> Thu, 20 Mar 2008 17:09:19 -0700
Newsgroups gmane.comp.windows.dotnet.nunit.devel
Message-ID <001401c88ae7$ddc039a0$6501a8c0@ferrari>
Hi Andreas, 

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

It's a good question. It would probably be easier to implement
separate interfaces but we may want to mix static with 
dynamic data at some point, which leads me to think that  we
should at least have a single interface - if not a single
extension point. I guess we'll let the code tell us. :-)
 
> 
> > 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.

Good, I was hoping you would. How do you want to start?
 
> 
> > 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.

No answers on how it will look, but yes the idea is that there should
be an extension point in it somewhere.

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/