Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 446852

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: UIAssignee: 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 Flags
Sample test class none

Description Goutham Patala CLA 2014-10-13 06:36:33 EDT
I am able to run a junit test class with Parameterized runner. But, when I try to run a selective(individual) test, the junit4 runner fails - the error is reported as 'Unrooted Tests'.
Comment 1 Goutham Patala CLA 2014-10-13 06:50:37 EDT
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.
Comment 2 Goutham Patala CLA 2014-10-13 06:52:57 EDT
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"}	
		});
	}
}
Comment 3 shankha banerjee CLA 2014-10-13 07:01:41 EDT
I was able to run:

In testOne :: passed in parameter::foo

In the LHS panel just select testOne and say run.
Comment 4 Goutham Patala CLA 2014-10-13 07:18:13 EDT
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.
Comment 5 shankha banerjee CLA 2014-10-13 07:27:14 EDT
(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
Comment 6 Goutham Patala CLA 2014-10-13 07:32:27 EDT
I have posted this bug only after thoroughly going through the documentation on Parameterized runner.
Comment 7 shankha banerjee CLA 2014-10-13 07:34:25 EDT
User may have few more queries.
Comment 8 shankha banerjee CLA 2014-10-13 08:53:54 EDT
(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 ?
Comment 9 Srikanth Sankaran CLA 2014-10-13 09:21:29 EDT
Pass to JDT/Ui for comment.
Comment 10 Noopur Gupta CLA 2014-10-13 09:36:33 EDT

*** This bug has been marked as a duplicate of bug 434093 ***
Comment 11 Moritz Eysholdt CLA 2014-10-13 09:41:17 EDT
There is already a fix for this in Gerrit:
https://git.eclipse.org/r/#/c/33189/