Re: Data-driven Tests in NUnit 2.5
Gary Evans <[email protected]> Mon, 17 Mar 2008 19:49:14 +0000
| Newsgroups | gmane.comp.windows.dotnet.nunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Charlie,
> For static data, NUnit can construct separate> test cases at load time for each set of arguments.> For dynamic data, this would be possible with some> changes, but I'm making a design decision not to> do it at this point.>
> 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 wondered what the reasoning behind this is - my addin that works with NUnit 2.4.6 populates the tree for both static and dynamic data.
> 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.>
It looks good - my addin just uses a string but it isn't that great that it's just a string reference. You haven't said what contract your data source object will have - will it implement a specific interface, or decorate a method?
Also, what interface will the method/property you call have - I have my addin call a property that returns IList<ParameterizedTestData>, but Kelly's original suggestion was to have an IEnumerable property.
It all looks good though!
Oh, when you say that you may have NUnit implement TestCase natively - will there still be a way for us to use the same underlying mechanism (i.e. we may want a different syntax on top for some reason, maybe for creating a MBUnit addin?)
> > I left out one thing - a question.> > If a fixture contains testcases like this...> > [TestCase( 1000, 10, 100.0000)]> [TestCase(-1000, 10, -0.0000)]> [TestCase( 1000, 7, 142.85715)]> [TestCase( 1000, 0.00001, 100000000)]> [TestCase(4195835, 3145729, 1.3338196)]> > ... it would be possible to have the five test> cases in the tree directly under the fixture or> to group them in a further level named for the> method as RowTest does.>
I prefer the second, that's what I've got in my addin, and (a poor attempt at drawing) my tree looks like
|-DivisionTest
|-|-Case1
|-|-Case2
but I force the user to specify the names of the test cases
[InlineData("Case1", new object[] { 1000, 10, 100.0000 })][InlineData("Case2", new object[] {-1000, 10, -0.0000 })]
public void DivisionTest(...
I don't know whether anyone finds this useful or not?
Cheers,
Gary
_________________________________________________________________
Telly addicts unite!
http://www.searchgamesbox.com/tvtown.shtml
-------------------------------------------------------------------------
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