JustDummies

Just dummies — but seriously powerful ones.

Documentation sections

JD007: DrawOutsideThePinnedScope

PropertyValue
CategoryReproducibility (JustDummies.Reproducibility)
Severity🟠 Warning
Enabled by defaultYes

[Reproducible] pins the seed from an xUnit before/after hook. xUnit constructs the test-class instance — and awaits IAsyncLifetime.InitializeAsyncbefore running those hooks, so anything drawn during construction comes from the unseeded ambient source.

The result is worse than no reproducibility at all: the test advertises it. The failure prints “Reproduce this run with [Reproducible(Seed = 1234)], the reader pins 1234, the arrangement still differs, the failure does not come back, and the seed looks broken.

Draw inside the test body, or hold the generator in the field and materialize it per test.

Noncompliant

[Reproducible]
public class OrderTests {
    private readonly string _reference;

    public OrderTests() {
        _reference = Any.String().StartingWith("ORD-").Generate();   // JD007: drawn before the seed is pinned
    }

    [Fact]
    public void It_is_accepted() { /* uses _reference */ }
}

Compliant

[Reproducible]
public class OrderTests {
    // The recipe is safe to share: the random source is resolved at Generate(), not at construction.
    private readonly IAny<string> _reference = Any.String().StartingWith("ORD-");

    [Fact]
    public void It_is_accepted() {
        string reference = _reference.Generate();   // drawn inside the pinned scope
    }
}

What it does not flag

  • A draw in the test body, which is inside the scope — verified against xunit.v3 by probe before this rule was written.
  • A draw from an isolated Any.WithSeed(...) context: that context is unaffected by the ambient scope by design, so reporting it would be wrong.
  • A generator reached through a local, a field or a parameter rather than written inline from Any. The rule only reports a chain it can prove starts at the ambient source, which under-reports rather than misfiring.
  • An IClassFixture<T> constructor. The fixture type does not itself carry [Reproducible], so the rule cannot see the link; the draw is equally unpinned, and the help page is the only warning you get.

Read the source, or correct it there opens in a new tab· Mirrored from lib-v1.0.0-preview.6