Skip to content
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

throw IllegalStateException if methodInvoker is Fail #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

t-izbassar
Copy link

Added throwing illegalStateException as if it is not added then this error is masked by RuntimeException with message "Cannot find invoker for the parameterised method. Using wrong JUnit version?" which might not be the case for test methods in which there are some instantiation problem.

As a client of this I was forced to debug library to see what happens. So here is PR.

@woprzech
Copy link
Contributor

Hello, thank you for your PR!

Can you describe what was a reason of the problem? Maybe we can suggest something to user in exception message because Instantiation failed is quite generic message.

Is it possible to write test for it? Just to make sure that problem will be solved?

@t-izbassar
Copy link
Author

Hello.

I've faced something similar to what was addressed in this issue. Will get exact reasons and versions and give more insights.

And yes, will try to write test and overall improve the PR. Thanks for response.

@goostleek
Copy link
Contributor

goostleek commented Jan 3, 2018

I have experienced the same issue. If I have a parametrized test that is set up in the constructor and the constructor throws an exception

@RunWith(JUnitParamsRunner.class)
public class FailingTest {

    public FailingTest() {
        throw new RuntimeException();
    }

    @Test
    public void aTest() {}

}

then the fail message is not accurate and the actual exception is swallowed (no stack trace available):

java.lang.RuntimeException: Cannot find invoker for the parameterised method. Using wrong JUnit version?

	at junitparams.internal.ParameterisedTestMethodRunner.findParameterisedMethodInvokerInChain(ParameterisedTestMethodRunner.java:75)
	at junitparams.internal.ParameterisedTestMethodRunner.findChildForParams(ParameterisedTestMethodRunner.java:61)
	at junitparams.internal.ParameterisedTestMethodRunner.runTestMethod(ParameterisedTestMethodRunner.java:38)
	at junitparams.internal.ParameterisedTestClassRunner.runParameterisedTest(ParameterisedTestClassRunner.java:146)
	at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:446)
	at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:393)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

The issue is especially annoying when you have only parametrized test cases in your test class because you will see no exception thrown from a constructor unless you have at least one regular (parametless) test case (in that case the exception can be seen in test case initialization).

try {
methodInvoker.evaluate();
} catch (Throwable throwable) {
throw new IllegalStateException("Instantiation failed", throwable);
Copy link
Contributor

@goostleek goostleek Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think calling methodInvoker.evaluate() would be enough for the fix. Ther's no need to catch the evaluation result and wraping up the original cause in IllegalStateException. WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for that is that evaluate is throwing Throwable and thus method findParametr... will not compile.

@goostleek
Copy link
Contributor

@t-izbassar Do you have plans to complete the PR by adding a missing test case for the fix (as suggested by the maintainers)?

@t-izbassar
Copy link
Author

@goostleek would like to do it but I was caught in trying to get better solution and for testing purposes there are no specific test cases for this class, so eventually I've switched to other things) but if someone like to finish it I have no problem with that. Will try to return this PR to my to-do list, but there are no timing guarantees)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants