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

Not compatible with JUnitParams when using @PowerMockRunnerDelegate(JUnitParamsRunner.class #685

Closed
wangjingfei opened this issue Jul 28, 2016 · 0 comments

Comments

@wangjingfei
Copy link

wangjingfei commented Jul 28, 2016

I have the following unit test:

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;

import static org.junit.Assert.assertTrue;

/**
 * Created by fify on 7/28/16.
 */
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(JUnitParamsRunner.class)
public class PowerMockWithJUnitParamsTest {
    @Test
    @Parameters({"1, 2, 3", "3, 4, 7"})
    public void testParameters(int a, int b, int check) {
        assertTrue(a + b == check);
    }
}

But when I ran it, the following exception was thrown:

java.lang.IllegalStateException: No match found
    at java.util.regex.Matcher.group(Matcher.java:536)
    at java.util.regex.Matcher.group(Matcher.java:496)
    at org.powermock.modules.junit4.internal.impl.NotificationBuilder.determineTestMethod(NotificationBuilder.java:141)
    at org.powermock.modules.junit4.internal.impl.NotificationBuilder.access$000(NotificationBuilder.java:37)
    at org.powermock.modules.junit4.internal.impl.NotificationBuilder$OngoingTestRun.<init>(NotificationBuilder.java:85)
    at org.powermock.modules.junit4.internal.impl.NotificationBuilder.testStartHasBeenFired(NotificationBuilder.java:231)
    at org.powermock.modules.junit4.internal.impl.PowerMockRunNotifier.fireTestStarted(PowerMockRunNotifier.java:109)
    at org.junit.internal.runners.model.EachTestNotifier.fireTestStarted(EachTestNotifier.java:42)
    at junitparams.internal.ParameterisedTestMethodRunner.runMethodInvoker(ParameterisedTestMethodRunner.java:45)
    at junitparams.internal.ParameterisedTestMethodRunner.runTestMethod(ParameterisedTestMethodRunner.java:40)
    at junitparams.internal.ParameterisedTestClassRunner.runParameterisedTest(ParameterisedTestClassRunner.java:146)
    at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:417)
    at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:386)
    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.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:143)
    at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:136)
    at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.withContextClassLoader(DelegatingPowerMockRunner.java:127)
    at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.run(DelegatingPowerMockRunner.java:136)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

The DisplayName passed with description.getDisplayName() looks like

[0] 1, 2, 3 (testParameters)(cn.irenshi.biz.attendance.service.PowerMockWithJUnitParamsTest)

But the org.powermock.modules.junit4.internal.impl.NotificationBuilder only accepts descriptions matches ^[^\(\[]++.

Although there is a workround, I think we should accept more method description formats.


Workaround: Set the JUnitParams.flat system property.
For example, if you use maven, you can set it like:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <systemPropertyVariables>
            <JUnitParams.flat>true</JUnitParams.flat>
        </systemPropertyVariables>
    </configuration>
</plugin>
@wangjingfei wangjingfei changed the title Not compatiable with JUnitParams when using @PowerMockRunnerDelegate(JUnitParamsRunner.class) Not compatible with JUnitParams when using @PowerMockRunnerDelegate(JUnitParamsRunner.class Jul 28, 2016
@thekingn0thing thekingn0thing added this to the PowerMock 1.6.7 milestone Nov 11, 2016
@thekingn0thing thekingn0thing modified the milestones: PowerMock 1.7.0, PowerMock 1.7.1 Feb 17, 2017
@thekingn0thing thekingn0thing modified the milestone: PowerMock 1.7.1 Jun 16, 2017
baurceanu pushed a commit to baurceanu/powermock that referenced this issue Aug 9, 2019
…ng compatibility with pl.pragmatists:JUnitParams before 1.0.6
odl-github pushed a commit to opendaylight/odlparent that referenced this issue Oct 22, 2019
No official release notes (yet?), the following issues are fixed:
powermock/powermock#685
powermock/powermock#992
powermock/powermock#939

Change-Id: Ie8266a961c75cb0dcb606e4639ef0b91a8992b5e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
odl-github pushed a commit to opendaylight/odlparent that referenced this issue Oct 23, 2019
No official release notes (yet?), the following issues are fixed:
powermock/powermock#685
powermock/powermock#992
powermock/powermock#939

Change-Id: Ie8266a961c75cb0dcb606e4639ef0b91a8992b5e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 3479902)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants