Skip to content
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

[junit-platform] Container failures don't cause Gradle failure #4175

Closed
kriegfrj opened this issue Jun 21, 2020 · 2 comments · Fixed by #4176
Closed

[junit-platform] Container failures don't cause Gradle failure #4175

kriegfrj opened this issue Jun 21, 2020 · 2 comments · Fixed by #4176

Comments

@kriegfrj
Copy link
Contributor

The Gradle plugins (and I'm assuming the Maven ones too) rely on the tester returning a non-zero value from System.exit() to signify that at least one test failure has occurred.

The way it has been written, junit-platform tester returns the number of test failures, but if you have only container failures it will return zero. Such situations are not uncommon - here is an example (admittedly contrived) that illustrates the point:

class MyTestClass {
  @BeforeAll
  void beforeAll()  {
    throw new IllegalStateException();
  }

  @Test
  void myTest() {
  }
}

When this class is run, the beforeAll() will fail and Jupiter will register the test container has having failed. Moreover, it will skip all of the test methods, so myTest() will not register as a failure (or as a success for that matter). So the overall test result will be a single container failure and no test failures. Because junit-platform returns the test failure count and not the total failure count, the exit value will therefore be zero, meaning that Gradle will incorrectly conclude that the tests passed.

This is a significant issue, though probably not significant enough on its own to warrant a new release. If we are doing a new minor release at some point it would probably be worth cherry-picking this fix into it as the fix will be simple and low-risk.

kriegfrj added a commit to kriegfrj/bnd that referenced this issue Jun 21, 2020
This is necessary as Jupiter reports container failures separately
from the children if the container fails before the children are
executed.

Fixes bndtools#4175.

Signed-off-by: Fr Jeremy Krieg <fr.jkrieg@greekwelfaresa.org.au>
@bjhargrave
Copy link
Member

I just hit this in porting OSGi compliance tests to junit-platform. Some test cases relied upon Bnd calling the setBundleContext method (which junit-platform does not do) and then NPE'd in setUp because the context field had not been set. And no errors were reported!

@kriegfrj
Copy link
Contributor Author

So sorry! Such an annoying bug, I'm a bit annoyed I didn't pick it up during development...

So do I interpret this as "let's do a 5.1.2 release"? 😄

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants