Re: Data-driven Tests in NUnit 2.5

"Kelly Anderson" <[email protected]> Mon, 17 Mar 2008 15:24:16 -0600
Newsgroups gmane.comp.windows.dotnet.nunit.devel
Message-ID <[email protected]>
On Sun, Mar 16, 2008 at 7:02 PM, Charlie Poole
<[email protected]> wrote:
>  For dynamic data, this would be possible with some
>  changes, but I'm making a design decision not to
>  do it at this point.

Having looked at the code, I think this is the better part of valor...
as it would require a pretty major restructuring of things.

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

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

Sure, that could work.

>  The actual interfaces involved still need to be
>  worked out.

Yeah.. :-)

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

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

>  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? Could the tests be written
in 2.0 code to test against 1.1 code?

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