Skip to content

Handle exceptions properly in SpringJUnit4ClassRunner [SPR-12613] #17214

@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-12613 and commented

Status Quo

SpringJUnit4ClassRunner has extended BlockJUnit4ClassRunner for several years and inherited default JUnit behavior from BlockJUnit4ClassRunner. At times, the default behavior needed to be copied and modified for special needs of the Spring TestContext Framework. For example, the BlockJUnit4ClassRunner.runChild() method has always been overridden in order to support Spring's @IfProfileValue annotation for ignored tests.

In JUnit 4.9, the implementation of BlockJUnit4ClassRunner.runChild() changed such that the invocation of BlockJUnit4ClassRunner.methodBlock() is no longer wrapped in a try-catch block. The end result is a change in backwards compatibility. Namely, any exceptions thrown from methodBlock() are no longer properly associated with the currently executing test method. Consequently:

  1. such failures are displayed as "unrooted" (i.e., not associated with the corresponding test method)
  2. all subsequent test methods for the current test class are not executed at all
  3. JUnit test listeners are not notified of such failures or of any subsequent test methods that should have been executed

In conjunction with #16527, SpringJUnit4ClassRunner was updated to use the aforementioned changes to BlockJUnit4ClassRunner.runChild() introduced in JUnit 4.9. As a consequence, this introduces a regression in SpringJUnit4ClassRunner which can be seen in test failures in TimedSpringRunnerTests.


Deliverables

  1. Ensure that any exceptions thrown within SpringJUnit4ClassRunner.methodBlock() are properly associated with the currently executing test.
  2. Inform the JUnit team of the regression they introduced in JUnit 4.9

Affects: 4.1 GA

Issue Links:

Referenced from: commits b81c522, 7d171e6

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions