JUnitParams icon indicating copy to clipboard operation
JUnitParams copied to clipboard

throw IllegalStateException if methodInvoker is Fail

Open t-izbassar opened this issue 7 years ago • 5 comments

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.

t-izbassar avatar Nov 17 '17 10:11 t-izbassar

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?

woprzech avatar Nov 20 '17 21:11 woprzech

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.

t-izbassar avatar Nov 20 '17 21:11 t-izbassar

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).

goostleek avatar Jan 03 '18 15:01 goostleek

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

goostleek avatar Jan 03 '18 15:01 goostleek

@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)

t-izbassar avatar Jan 03 '18 15:01 t-izbassar