-
Notifications
You must be signed in to change notification settings - Fork 746
Tests should pass if test case source provides 0 test cases #1933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If memory serves (I can check the code tomorrow) NUnit is actually creating a fake test so that there will be a place to report the error back to you. This may not be the best way to handle the problem. |
@CharliePoole @nunit/contributors I added failing tests for the expected behavior. Just double checking that this is the correct goal. jnm2@2a7e5a2 |
@nunit/core-team @nunit/framework-team We need to agree whether this issue is a bug or just how NUnit is intended to work. @jnm2 has already created a simple PR to fix it if we want it fixed. I see no reason to fail for zero test cases supplied except possibly in the case of theories. What do others think? |
I see no reason to fail for zero tests supplied in any case. It should be a noop. |
In the case of theories, which are not dealt with in the PR, we define passing to mean at least one test case passed all assumptions and all of those that passed the assumptions also passed the assertions. It's a higher standard than normal tests. It seems to me that not finding any data at all is pretty much the same as finding data where none of it qualifies for use under the stated assumptions. I think theories can take care of themselves here, just as they normally do with their altered definition of success. We should add a test to make sure we don't break that. |
A while back we had a discussion about whether fixtures with no tests should fail and decided that was not a cause for failure. I think that parameterized method suites should be treated the same way. |
We already have TheoryWithNoDatapointsIsNotRunnable and it is doing its job, as I just found out. |
OK, that's as I had hoped. My only quibble is with the Any statement used in the query. Since the code above that point just figured out how many builders there are and iterated through them, it seems silly to waste a Linq query on figuring it out all over again. Does testing |
@rprouse I'd like to be sure that you agree with us on the behavior before OKing the merge... |
No. There are two problems with it.
|
To deal with the two failing theory tests, we have two options:
|
Correction. I'm not longer convinced that leaving zero-case theories as suites is the best experience. Probably better to turn them into single tests as they always have been. I just wish a better message was available than "arguments not provided," such as "no test cases were conclusive." I'm on the fence. Opinions? |
I've never used a theory so I have no input. |
"All test cases were inconclusive" is a Theory-specific failure (not error) message that we don't want to lose. It should only occur when there were test-cases and all of them failed there assumptions. Theories are suites. They are defined to fail when any test case fails or all cases are inconclusive. The message should never occur for tests that are not theories. If it does it's a bug, although maybe a different one from this. |
I agree. I did not mean to suggest that this message would occur for non-theory tests. Edited. |
@jnm2 Theory is an example of a type of test that has it's own rules for failure and success. Ideally, those rules should always be encapsulated in the attribute itself. Any time we are using the Type of a specific attribute to make a decision in the framework, we should consider it a smell. We may be violating that encapsulation. This seems to be such a case. 😄 OTOH, the code we are looking at is responsible for building single test cases and suites of parameterized test cases (which includes Theory). It should result in a non-runnable test case or suite iff it is unable to build a test that will run. Currently, we do that indirectly by letting either of the two lower-level methods we call generate a non-runnable test depending on whether or not the right number of arguments are found. It seems as if allowing a parameterized test with no data to pass might be breaking this strategy so that we need a new one. Just thinking out loud. I'm going to look more closely at the code before continuing. |
@jnm2 You do seem to find those issues that look simple but have depths. 😄 |
@CharliePoole My first idea was, have TheoryAttribute override
This thought has come to mind not infrequently. What is it about me that my workflow usually exercises all the paths less traveled no matter what the library is? :-p |
Ooh, and now I'm up against the fact that treating I dunno, is it me? O.o |
Okay, the TheoryAttribute needs a way to cause the parameterized method suite (which is built after the fact) to be not runnable.
|
An exception is often appropriate though. See CombiningStrategyAttribute.BuildFrom. If there is some problem constructing the suite (which for theories with zero cases, there is), it coudl throw an exception and have the exception message represented on the empty suite. |
I'm expecting some good critiques, but I just committed what I think is the basis of a good solution. |
I also think zero test cases shouldn't fail the tests. I will throw one option out there though, should/can we use the new warnings for this? That way it will not fail the test, but people who thought they have data will be warned? |
Uh oh!
There was an error while loading. Please reload this page.
I'm in a situation where I need to run a set of integration tests sets against multiple databases. It's been extremely helpful to use TestCaseSource to give separate test cases for each object in certain database tables. In fact, this is what motivated the move to NUnit in the first place.
The only issue is that it's perfectly valid for tables to be empty. In that scenario, I would expect that no test cases would exist or be run. Surprisingly, and problematically, even though I'm returning an empty
IEnumerable<TestCaseData>
from the test case source, NUnit still attempts to run the test anyway as a single case with no arguments. And of course the test fails, since the arguments are necessary.Is this helpful behavior or a bug? If this is helpful behavior to some people, can I globally configure NUnit to always consider 0 test cases as 0 test cases which matches my intuition and needs?
The text was updated successfully, but these errors were encountered: