Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jul 26, 2018

Overview

PR for Issue #1454
Make it possible to also handle exceptions thrown by BeforeEach/AfterEach methods via the TestExecutionExceptionHandler.
The new handler methods are default methods to make them optional and to not break the FunctionalInterface.
This PR is a proposal to solve the issue. It's not complete. The Javadoc is not adjusted and the exception handling for the BeforeAll/AfterAll methods is missing.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@ghost
Copy link
Author

ghost commented Jul 31, 2018

Added exception handling for BeforeAll/AfterAll methods

Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for the new exception handling callbacks.

for (Method method : this.beforeAllMethods) {
throwableCollector.execute(
() -> executableInvoker.invoke(method, testInstance, extensionContext, registry));
for (Method method: this.beforeAllMethods) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reintroduce the space between method and :.

@sbrannen
Copy link
Member

The build is currently broken due to formatting issues.

Run gradlew spotlessApply to fix these violations.

@ghost
Copy link
Author

ghost commented Jul 31, 2018

But where to put the tests (TestExecutionExceptionHandlerTests or BeforeAndAfterEachTests or a new class) without blowing up an existing class or repeating too much code in a new class?

@sbrannen
Copy link
Member

I'd probably just introduce a set of test classes parallel to the existing TestExecutionExceptionHandlerTests.

As for adhering to the DRY principle, just do your best. We can always refactor later. The main objective for starters is just having tests in place.

@sbrannen
Copy link
Member

and yeah.... please don't "blow up" anything. 😉

@marcphilipp marcphilipp modified the milestones: 5.3 RC1, 5.4 M1 Aug 3, 2018
@ghost
Copy link
Author

ghost commented Aug 7, 2018

Tests added

@ghost
Copy link
Author

ghost commented Aug 8, 2018

Finally removed the formatting issues - these checks are really pedantic...
Don't know why there is still a failure.

@jbduncan
Copy link
Contributor

jbduncan commented Aug 8, 2018

@phoenix384 Were you not able to simply run gradlew spotlessApply to fix all the formatting problems? 🤔

@sbrannen
Copy link
Member

sbrannen commented Aug 9, 2018

@phoenix384, you really shouldn't try to tackle formatting issues one-by-one.

Instead, as @jbduncan mentioned, you should simply execute gradlew spotlessApply once before committing your changes.

Alternatively, you can set up the formatting in your IDE.

This is all documented in the CONTRIBUTING documentation for JUnit 5.

@sbrannen
Copy link
Member

sbrannen commented Aug 9, 2018

The last failure appears to have something to do with Jacoco:

https://travis-ci.org/junit-team/junit5/jobs/413706488#L1467-L1486

Maybe that's just an intermittent issue on the CI server.

Does gradle build work consistently on your machine?

*/
void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable;

default void handleExceptionInBeforeAllMethod(ExtensionContext context, Throwable throwable) throws Throwable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Team Decision: Please rename all newly introduced methods to better align with the naming convention of the previously existing method, e.g. handleBeforeAllMethodExecutionException etc.

@marcphilipp marcphilipp modified the milestones: 5.4 M1, 5.4 M2 Nov 23, 2018
@sormuras sormuras modified the milestones: 5.4 RC1, 5.4 GA Jan 11, 2019
@marcphilipp marcphilipp modified the milestones: 5.4 GA, 5.5 M1 Jan 25, 2019
@ghost
Copy link
Author

ghost commented Feb 8, 2019

5.4 is released and this is still not merged. Is there a reason?

@sbrannen
Copy link
Member

sbrannen commented Feb 8, 2019

Hi @phoenix384,

5.4 is released and this is still not merged. Is there a reason?

Yes, requested changes have not yet been made (e.g., #1509 (comment)), and the following tasks under "Definition of Done" have not been addressed.

Please rebase on master and address those 3 tasks, and we'll make sure to review it again and get it into JUnit 5.5.

Thanks!

@sbrannen sbrannen changed the title Exception handling for BeforeEach/AfterEach methods (issue 1454) Introduce exception handling support for lifecycle callback methods Feb 8, 2019
@marcphilipp marcphilipp modified the milestones: 5.5 M1, 5.5 M2 Mar 8, 2019
@marcphilipp marcphilipp modified the milestones: 5.5 M2, 5.5 Backlog Apr 18, 2019
@marcphilipp marcphilipp removed this from the 5.5 Backlog milestone May 3, 2019
@marcphilipp
Copy link
Member

Closing in favor of #1868.

@marcphilipp marcphilipp closed this May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants