Nunit: Empty result from `TestCaseSource` generator should fail the test

Created on 3 Jun 2020  ·  3Comments  ·  Source: nunit/nunit

When using [TestCaseSource(nameof(GeneratorMethod))], it would make sense to fail the test (or mark it as skipped) if the generator produces no inputs. At least don't show the test as passing :/

Most helpful comment

Some points to consider...

  1. There can be multiple sources, so we need to be clear about whether the discussion applies to __each__ source or to the aggregate result of all sources.

  2. Sources generate tests, not just data. If no tests are generated, then there is nothing to fail or skip. In the distant past (V2) we generated a fake failing test, that ended up being both messy in the code and confusing to the users.

  3. A test method with no cases is a bit like a method with no code. Also like a fixture with no tests. We consider those passing.

  4. If you call your test a theory, you will get a failure if there is no passing case.

I'd vote for leaving the current behavior but giving the user some way to ask for a warning message if no cases are generated.

All 3 comments

If memory serves, it works as it does due to a bug report some years back, which convinced us it should pass in this case.

😢

I just wrote a test with (currently) one item in the source, and, being a new test in a TDD cycle, I expected it to fail, only to find it passed... so I had to track down my faulty generator.

Perhaps failure is a bit to draconian (my preference, but may be annoying to the reporter of the prior issue). How about marking the test as skipped?

Some points to consider...

  1. There can be multiple sources, so we need to be clear about whether the discussion applies to __each__ source or to the aggregate result of all sources.

  2. Sources generate tests, not just data. If no tests are generated, then there is nothing to fail or skip. In the distant past (V2) we generated a fake failing test, that ended up being both messy in the code and confusing to the users.

  3. A test method with no cases is a bit like a method with no code. Also like a fixture with no tests. We consider those passing.

  4. If you call your test a theory, you will get a failure if there is no passing case.

I'd vote for leaving the current behavior but giving the user some way to ask for a warning message if no cases are generated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Thaina picture Thaina  ·  5Comments

xplicit picture xplicit  ·  5Comments

ChrisMaddock picture ChrisMaddock  ·  3Comments

ffMathy picture ffMathy  ·  3Comments

Prodigio picture Prodigio  ·  3Comments