Theory and Datapoints

Bug #629661 reported by Rechenelf
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
New
Undecided
Unassigned

Bug Description

We should avoid usinge the mechanism for parameterized test in theories. The following example has "exploding" combinatorical parameters. To avoid this, we must use ValueSource.

  [Datapoints]
  public double[] as = new double[] { 0.0, 1.0, -1.0, 42.0 };
  public double[] bs = new double[] { 0.0, 1.0, 100.0 };

  [Theory]
  public void Add(double num1, double num2)
  {
    Assert.That(num1 + num2 == num2 + num1);
  }

But it might be nicer if we really can avoid it using a new attribut Use:
  [Theory]
  public void Add([Use(as)] double num1, [Use(bs)] double num2)
  {
    Assert.That(num1 + num2 == num2 + num1);
  }

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 629661] [NEW] Theory and Datapoints

Hi,

You should be aware that Theories are somewhat experimental and underdeveloped
right now with significant changes planned for 3.0. The basic idea of
theories is that
the developer does _not_ control what test cases will be generated.

In the current NUnit implementation, I allowed use of the standard
data parameters
to supplement any data generated by NUnit, thereby guaranteeing that some
particular test cases will be used. Such test cases will probably be treated
differently in the future.

I'm moving this feature request to the 3.0 project so it can serve as a reminder
of the issues you are raising there.

Charlie

On Fri, Sep 3, 2010 at 9:59 AM, Rechenelf <email address hidden> wrote:
> Public bug reported:
>
> We should avoid usinge the mechanism for parameterized test in theories.
> The following example has "exploding" combinatorical parameters. To
> avoid this, we must use ValueSource.
>
>  [Datapoints]
>  public double[] as = new double[] { 0.0, 1.0, -1.0, 42.0 };
>  public double[] bs = new double[] { 0.0, 1.0, 100.0 };
>
>  [Theory]
>  public void Add(double num1, double num2)
>  {
>    Assert.That(num1 + num2 == num2 + num1);
>  }
>
>
> But it might be nicer if we really can avoid it using a new attribut Use:
>  [Theory]
>  public void Add([Use(as)] double num1, [Use(bs)] double num2)
>  {
>    Assert.That(num1 + num2 == num2 + num1);
>  }
>
> ** Affects: nunitv2
>     Importance: Undecided
>         Status: New
>
>
> ** Tags: attribute datapoint feauture theory use
>
> --
> Theory and Datapoints
> https://bugs.launchpad.net/bugs/629661
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
>

tags: added: feature theories
removed: datapoint feauture theory use
affects: nunitv2 → nunit-3.0
Revision history for this message
Rechenelf (matklaus) wrote :

I thougt after reading the manual that theory is the general test not depends on special data. But the programmer only can give the borders and data, which might be a problem.
By the way, what I have missed in the manual: Assume is for precondition, Assert for postcondition and it can be used for programming by contract.

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Assume is only similar to a precondition - it is not an error if an assume fails and the test case is simply not used.
If all test cases fail the assumptions then the theory fails. If any test cases fail the Asserts then the theory fails.

For a more general discussion about this, if you would like it, please ask on the nunit-discuss list.

tags: added: framework
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.