Browse Source

Handle exceptions properly in SpringJUnit4ClassRunner

JUnit 4.9 introduced a regression in BlockJUnit4ClassRunner.runChild()
such that exceptions thrown from methodBlock() cause the current test
execution to abort immediately. As a result, the failing test method is
unrooted, and subsequent test methods are never invoked. Furthermore,
RunListeners registered with JUnit are not properly notified.

In conjunction with SPR-11908, SpringJUnit4ClassRunner was updated to
use the aforementioned changes to BlockJUnit4ClassRunner.runChild().
Consequently, SpringJUnit4ClassRunner now suffers from the same
regression.

This commit addresses this issue by ensuring that any exceptions thrown
during the invocation of methodBlock() are properly wrapped in a JUnit
Fail Statement.

Issue: SPR-12613
pull/719/head
Sam Brannen 10 years ago
parent
commit
b81c522ee1
  1. 11
      spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java

11
spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -214,7 +214,14 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { @@ -214,7 +214,14 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
notifier.fireTestIgnored(description);
}
else {
runLeaf(methodBlock(frameworkMethod), description, notifier);
Statement statement;
try {
statement = methodBlock(frameworkMethod);
}
catch (Throwable ex) {
statement = new Fail(ex);
}
runLeaf(statement, description, notifier);
}
}

Loading…
Cancel
Save