| Summary: | [JUnit] Unable to run a junit test individually when the test class is run with Parameterized runner | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Goutham Patala <goutham.general> | ||||
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> | ||||
| Status: | CLOSED DUPLICATE | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | goutham.general, moritz.eysholdt, noopur_gupta, shankhba, srikanth_sankaran | ||||
| Version: | 4.5 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Goutham Patala
Created attachment 247833 [details]
Sample test class
Attached is a sample test class. It contains two test methods. We should be able to run the test class as a single unit which runs both the test methods. It fails when we select one test method and try to run it.
Pasting the test class below as the attachment seems to be not uploaded as anticipated.
----------------------------------------------------------------------------
----------------------------------------------------------------------------
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParameterizedTest {
private String p_testParam;
public ParameterizedTest(String p_testParam) {
this.p_testParam = p_testParam;
}
@Test
public void testOne() {
System.out.println("In testOne :: passed in parameter::"+p_testParam);
}
@Test
public void testTwo() {
System.out.println("In testTwo :: passed in parameter::"+p_testParam);
}
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{"foo"},
{"bar"},
{"baz"}
});
}
}
I was able to run: In testOne :: passed in parameter::foo In the LHS panel just select testOne and say run. That's strange output. You should be getting three output statements like below if it is run parameterized way. As you are getting only one output statement, it means that the test class isn't run with the 'Parameterized' runner as annotated. In testOne :: passed in parameter::foo In testOne :: passed in parameter::bar In testOne :: passed in parameter::baz (In reply to shankha banerjee from comment #3) > I was able to run: > > In testOne :: passed in parameter::foo > > In the LHS panel just select testOne and say run. (In reply to Goutham Patala from comment #4) > That's strange output. You should be getting three output statements like > below if it is run parameterized way. As you are getting only one output > statement, it means that the test class isn't run with the 'Parameterized' > runner as annotated. > > In testOne :: passed in parameter::foo > In testOne :: passed in parameter::bar > In testOne :: passed in parameter::baz > Please read: http://junit.sourceforge.net/javadoc/org/junit/runners/Parameterized.html I have posted this bug only after thoroughly going through the documentation on Parameterized runner. User may have few more queries. (In reply to Goutham Patala from comment #6) I understand the question. import org.junit.Test; public class TestJunit1 { String message = "Robert"; @Test public void hello1() { System.out.println("Inside 1"); } @Test public void hello2() { System.out.println("Inside 2()"); } } What you meant is if one can run individual junits : hello1 and hello2 by just selecting one of them and then run them as junit, why not the same with Parameterized.class ? Pass to JDT/Ui for comment. *** This bug has been marked as a duplicate of bug 434093 *** There is already a fix for this in Gerrit: https://git.eclipse.org/r/#/c/33189/ |