Re: Data-driven Tests in NUnit 2.5
"Charlie Poole" <[email protected]> Wed, 19 Mar 2008 07:37:52 -0700
| Newsgroups | gmane.comp.windows.dotnet.nunit.devel |
|---|---|
| Message-ID | <007a01c889ce$d3bff4a0$6701a8c0@ferrari> |
Hi Kelly,
> > That means that test cases created with static data will
> show up in
> > the tree of tests individually.
> > Those constructed with dynamic data will not show up
> separately, but
> > will produce separate results when the tests are run. Tests are
> > already capable of returning multiple results in NUnit but
> the Gui
> > will need to be modified to display them.
>
> I would assume that there will also have to be some sort of
> notification that the GUI can pick up...
The existing events will work but may need to carry some extra information.
> > 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);
> > }
> > }
>
> Why not [Test(1000, 7, 142.85715)] ??? Is there a naming conflict?
1) Test already means a lot of things in NUnit. TestCases, TestSuites
TestFixtures, etc. are all Tests.
2) A new name for a new thing
3) Not breaking compatibility with old apps
4) Test already takes an argument: the description.
> > 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.
>
> I see where you're trying to go with the type safe thing
> here. That makes some sense... but don't you still have a
> problem extracing numerator, denominator and result from
> MyDataSource? That part would want to be type safe too, wouldn't it?
The interface can be type safe, the actual returned values need to
be tested for a match to the argument types dynamically. That's no
big deal since large parts of NUnit already work this way.
> > More to come on this - your comments are welcome.
>
> I'll give some thought to a type safe way to do this... do
> you have anything against using generics? Or would the fact
> that they aren't supported in 1.1 keep you off that track?
No, generics are a graeat approach for the 2.0 version of the runners.
> Could the tests be written in 2.0 code to test against 1.1 code?
Only to test them under 2.0. That may be OK for some purposes though.
Charlie
> -Kelly
>
> --------------------------------------------------------------
> -----------
> 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/
> _______________________________________________
> nunit-developer mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-developer
>
-------------------------------------------------------------------------
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/