-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Parameterized tests: misleading error if exception was thrown in static initializer #3054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's the "suppressed" exception. The actual exception that is thrown is the
In Eclipse IDE, one sees the Does IntelliJ display the suppressed exception instead of the top-level exception? |
I am not familiar with the concept of "suppressed" exceptions. Like all Java developers I am used to scrolling down lengthy stacktraces hoping for a clue about what's going on. In my experience it's the plain text phrases that provide the most help. Such as "Configuration error: You must configure at least one set of arguments for this @ParameterizedTest". Only in this case, that's not what's going on at all. My suggestion would be to simply not have that in the stack trace. |
Well, I can see that it's a bit confusing but it did indeed fail to provide at least one set of arguments because it tried to load the test class in order to invoke the static method which failed which is indicated by the root cause. |
I am convinced the message makes perfect sense for anyone familiar with the internals of the API. As a user I found it confusing. I'd be interested in how other users see it, but since I'm the first one to report it, it may well be a "me-issue" 🙂 So feel free to close this and re-visit it if it turns out others feel the same! |
I agree that the message could be confusing in this case
I think the confusion lies in the |
Team decision: Investigate options for avoiding inclusion of the suppressed |
@marcphilipp @sbrannen if no one is working on this I would like to check it out, is it available to take a stab at? |
@BassemElMasry, this issue is labeled as So that means anyone can attempt to solve it and submit a PR. If you do start working on a PR, please post back here so that the community knows you're working on it. FYI: I looked into this issue, and at a glance it appears it might be slightly challenging. Specifically, the described behavior (a suppressed exception in a stream pipeline) is a direct result of the documented contract for |
Thank you @sbrannen for letting me know. I will take a look and try to come up with the solution and submit a PR. |
You're welcome.
OK. This is now assigned to you. Please keep us posted on your progress. |
Hello @sbrannen @marcphilipp , |
Hello @sbrannen @marcphilipp , I have been trying this for a while now, and the way I was able to achieve this was by introducing a new customized
any ideas of better ways to do this? |
@BassemElMasry I think Since the suppressed exception is thrown when the Lines 112 to 115 in f32aa0a
Changing that to the following should do the trick: Stream<TestTemplateInvocationContext> stream = invocationContexts(provider, extensionContext);
try {
stream.forEach(
invocationContext -> toTestDescriptor(invocationContext, invocationIndex.incrementAndGet()) //
.ifPresent(testDescriptor -> execute(dynamicTestExecutor, testDescriptor)));
}
catch (Throwable t) {
try {
stream.close();
} catch (Throwable t2) {
// ignore exceptions from close() to avoid masking the original failure
UnrecoverableExceptions.rethrowIfUnrecoverable(t2);
}
throw ExceptionUtils.throwAsUncheckedException(t);
} finally {
stream.close();
} |
@marcphilipp Thanks for replying Marc! I see, I will work on it |
@marcphilipp @BassemElMasry |
Hello, there. If possible, could you assign this to me please? |
Hello @YongGoose @marcphilipp @alihmzyv , Sorry did not respond for this period due to health reasons. Indeed I worked on it and will create the PR. Thanks! |
Happy to see you're feeling better. Great 🤝 |
When a parameterized test is executed, but an exception is thrown in the test class' static initializer, the error message is:
"Configuration error: You must configure at least one set of arguments for this @ParameterizedTest"
This distracts from the actual source of the problem. I know static initializers are generally frowned upon, but they are recommended for some edge cases, e.g. by the Testcontainers project.
Steps to reproduce
Context
Full error message
click here
The text was updated successfully, but these errors were encountered: