Yamikuronue
Yamikuronue

Reputation: 758

Cannot run single parameterized test method in eclipse

I am using Junit-4 to run some parameterized tests inside of Eclipse Luna. I can run a single class by right-clicking and selecting "run as -> JUnit Test", but if I expand the class and do the same action on a single method (to run only one test), I get an initialization error inside "Unrooted Tests". However, if I run the entire class worth of methods and then right-click on a single test in the results pane and click "run", it runs just fine.

How can I set up JUnit so that I can run a single test method without having to run the whole class first? What configuration options should I be looking at? It's a maven project, but I'm not sure that matters. Stepping through, I can see the issue occurs when JUnit attempts to run the test, after the parameters are generated successfully, but I cannot see the source code at that point, so my information is very limited. No error/exception details are shown :(

I'm pretty sure it's a configuration problem because I managed to reproduce the problem with the following test case:

@RunWith(Parameterized.class)
public class JUnitTesting {
    /**
     * Generates list of environments to use for the test.
     * @return The list of environments to pass to the constructor.
     */
    @Parameters
    public static synchronized  Collection<String[]> environmentsToUse() {
            LinkedList<String[]> environments = new LinkedList<String[]>();
            environments.add(new String[]{"WINDOWS", "firefox", null});
            environments.add(new String[]{"WINDOWS", "chrome", null});
            return environments;    
    }

    public JUnitTesting(String os, String browser, String version) {

    }

    @Test
    public void sampleTest() {
        System.out.println("Test run.");
    }
}

Upvotes: 1

Views: 2391

Answers (1)

E-Riz
E-Riz

Reputation: 32914

It was a known limitation of Eclipse's JUnit support in versions before Mars (4.5). Apparently also in IntelliJ. If you can't use a Mars milestone or release build, there is a workaround, if you're willing to use your own custom runner.

Upvotes: 4

Related Questions