| Property | Value |
|---|---|
| Category | Reproducibility (JustDummies.Reproducibility) |
| Severity | 🔴 Error |
| Enabled by default | Yes |
Any.ReproduciblyAsync returns a Task that faults with the body’s exception. Discarding it — as a standalone statement, or via _ = — lets a failing test pass green, because the failure is never observed. await the returned task.
The compiler’s own CS4014 does not catch this in a synchronous (void) test method, which is exactly where the mistake is easiest to make.
Noncompliant
[Fact]
public void A_20_percent_discount_takes_a_fifth_off_the_order() {
Any.ReproduciblyAsync(async () => { // JD002: the returned task is discarded
string anyReference = Any.String().StartingWith("ORD-").WithLength(12).Generate();
string anyCustomer = Any.String().Alpha().WithLengthBetween(1, 50).Generate();
Order order = new Order(anyReference, anyCustomer, amount: 100m);
order.ApplyDiscount(20);
await _repository.SaveAsync(order);
Assert.Equal(80m, order.Total);
});
}
_ = Any.ReproduciblyAsync(async () => { /* ... */ }); // JD002: the returned task is discarded
Compliant
[Fact]
public async Task A_20_percent_discount_takes_a_fifth_off_the_order() {
await Any.ReproduciblyAsync(async () => {
string anyReference = Any.String().StartingWith("ORD-").WithLength(12).Generate();
string anyCustomer = Any.String().Alpha().WithLengthBetween(1, 50).Generate();
Order order = new Order(anyReference, anyCustomer, amount: 100m);
order.ApplyDiscount(20);
await _repository.SaveAsync(order);
Assert.Equal(80m, order.Total);
});
}