nunit: Random attribute with Distinct and wide range causes test to disappear

Steps to reproduce

Create a new NUnit test project with this test class:

using NUnit.Framework;

namespace Repro;

public class Tests
{
    [Test]
    public void Test1(
        [Random(int.MinValue / 2, int.MaxValue / 2 + 1, count: 10, Distinct = true)] int i)
    {
        Assert.Pass();
    }
}

Run it with dotnet test.

Expected behaviour

The test runs and passes ten time.

Actual behaviour

No tests run.

No test is available in [redacted]\Repro\Repro\bin\Debug\net7.0\Repro.dll.
Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate
and try again.

More information

This seems to be related to the requested range of the random values. If you remove the + 1 the tests execute as expected:

[Test]
public void Test1(
    [Random(int.MinValue / 2, int.MaxValue / 2, count: 10, Distinct = true)] int i)
{
    Assert.Pass();
}

Alternatively, if you leave out the Distinct requirement, the tests also run as expected:

[Test]
public void Test1(
    [Random(int.MinValue / 2, int.MaxValue / 2 + 1, count: 10)] int i)
{
    Assert.Pass();
}

System information:

  • Windows 11 Pro 22H2
  • .NET 7

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16

Most upvoted comments