Bug #1946
Updated by Udo Offermann over 9 years ago
.h2 Problem
create a z2 unit test containing a private method with an @Test annotation.
org.junit.runners.ParentRunner will detect that this is an error and throws an InitializationError containing all violations:
<pre>
// inside indside ParentRunner
private void validate() throws InitializationError {
List<Throwable> errors = new ArrayList<Throwable>();
collectInitializationErrors(errors);
if (!errors.isEmpty()) {
throw new InitializationError(errors);
}
}
</pre>
Z2UnitTestRunner now catches all Exceptions and wraps them within a new @InitializationError@ so that the violations are hidden.
h2. Suggestion
rewrite
<pre>
public Z2UnitTestRunner(Class<?> klass) throws InitializationError {
this.clz = klass;
this.readConfig();
try {
if (this.runWithClass!=Runner.class) {
this.runWith = this.runWithClass.getConstructor(Class.class).newInstance(this.clz);
} else {
this.runWith = new BlockJUnit4ClassRunner(this.clz);
}
} catch (InitializationError e) {
// InitializationError must not be wrapped!
throw e;
} catch (Exception e) {
throw new InitializationError(e);
}
}
</pre>
