Version 5.10.0.
Steps to reproduce
- Create a custom extension that implements
BeforeEachCallback.
- In its
beforeEach() method make the extension put a CloseableResource into context's store.
- Make this
CloseableResource throw a (runtime) exception on closing.
Result: JUnit logs the exception and fails the current test.
Expected: the test fails, but exception is not logged.
Rationale: (apparently) all other exceptions simply make the test fail, but are not logged additionally. We use logging configuration that normally writes to a file (for later investigation), but additionally writes all messages with WARN and ERROR levels to console, for maximum visibility. This is very helpful in most cases, but here it makes the output contain duplicated stacktraces: once from the log (as said, ERRORs are duplicated to stderr by our configuration) and once from normal JUnit output, once the test fails.
Also, logging exceptions is practically a must when you "eat" them (i.e. don't rethrow, but also don't really handle), so they don't just get lost; and a possibility when said exception might get clobbered by something. But here it's not the case, because exception will make the current test fail and its stacktrace will be properly preserved.
Context
- Used versions (Jupiter/Vintage/Platform): JUnit 5.10.0
- Build Tool/IDE: Gradle (irrelevant)
If really needed I could create a reproducer, but would prefer to avoid this. I cannot use our codebase for this, as it is very complex and contains a lot of completely irrelevant stuff.
In JUnit's code the problem is here:
ExtensionContext extensionContext = getExtensionContext();
if (extensionContext instanceof AutoCloseable) {
try {
((AutoCloseable) extensionContext).close();
}
catch (Exception e) {
logger.error(e, () -> "Caught exception while closing extension context: " + extensionContext);
throw e;
}
}
As far as I see, you could just drop exception catching+logging+rethrowing and that would be it.
Version 5.10.0.
Steps to reproduce
BeforeEachCallback.beforeEach()method make the extension put aCloseableResourceinto context's store.CloseableResourcethrow a (runtime) exception on closing.Result: JUnit logs the exception and fails the current test.
Expected: the test fails, but exception is not logged.
Rationale: (apparently) all other exceptions simply make the test fail, but are not logged additionally. We use logging configuration that normally writes to a file (for later investigation), but additionally writes all messages with WARN and ERROR levels to console, for maximum visibility. This is very helpful in most cases, but here it makes the output contain duplicated stacktraces: once from the log (as said, ERRORs are duplicated to stderr by our configuration) and once from normal JUnit output, once the test fails.
Also, logging exceptions is practically a must when you "eat" them (i.e. don't rethrow, but also don't really handle), so they don't just get lost; and a possibility when said exception might get clobbered by something. But here it's not the case, because exception will make the current test fail and its stacktrace will be properly preserved.
Context
If really needed I could create a reproducer, but would prefer to avoid this. I cannot use our codebase for this, as it is very complex and contains a lot of completely irrelevant stuff.
In JUnit's code the problem is here:
As far as I see, you could just drop exception catching+logging+rethrowing and that would be it.