junit4 icon indicating copy to clipboard operation
junit4 copied to clipboard

Attempting to rerun failing JUnit 4 Parameterized tests in IDEA fails

Open Panthro opened this issue 6 years ago • 3 comments

When I have a test with

@Parameterized.Parameters(name = "{1} : {0}")

If I try to rerun failed tests in Intellij Idea, then I get:

java.lang.Exception: No tests found matching Tests from org.junit.runner.Request$1@5ae50ce6

	at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
	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)

If I leave the @Parameterized.Parameters without name it works, any idea?

Found a Junit5 related issue, https://github.com/junit-team/junit5/issues/1386

Junit version 4.12, can this be related or should I open another issue?

Panthro avatar Apr 12 '19 08:04 Panthro

In IDEA 2019.1 it works for me. As suggested in the mentioned junit5 issue - please try a newer version of IDEA

@RunWith(Parameterized.class)
public class Issue1604 {
    @Parameterized.Parameters(name = "{1} : {0}")
    public static List<Object[]> params() {
        return Arrays.asList(
                new Object[]{ "A", 1 },
                new Object[]{ "B", 2 }
        );
    }

    @Parameterized.Parameter(0)
    public String first;

    @Parameterized.Parameter(1)
    public Integer second;

    @Test
    public void test() {
        assertEquals((Integer) 1, second);
    }
}

panchenko avatar Apr 12 '19 11:04 panchenko

@Panthro Which version of IntelliJ IDEA are you using?

stefanbirkner avatar Apr 13 '19 12:04 stefanbirkner

I just ran into this problem.

"Rerun Failed Tests" fails if the parameterized test name has a "/" in it.

@RunWith(Parameterized.class)
public class ParaTest {
	@Parameterized.Parameters(name = "{0}")
	public static List<Object[]> params() {
		return Arrays.asList(
			new Object[]{ "a/1" },
			new Object[]{ "b/2" }
		);
	}

	@Parameterized.Parameter
	public String name;

	@Test
	public void test() {
		assertEquals("x", name);
	}
}

IntelliJ IDEA 2021.2 (Community Edition) Build #IC-212.4746.92, built on July 27, 2021 Runtime version: 11.0.11+9-b1504.13 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 10.15.7 GC: ParNew, ConcurrentMarkSweep Memory: 1979M Cores: 16 Kotlin: 212-1.5.10-release-IJ4746.92

felix9 avatar Aug 18 '21 17:08 felix9