Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 434093 - [JUnit] Execute single test method of parameterized junit test
Summary: [JUnit] Execute single test method of parameterized junit test
Status: CLOSED DUPLICATE of bug 443498
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 446852 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-05-05 07:12 EDT by Tobias Melcher CLA
Modified: 2014-11-04 10:04 EST (History)
9 users (show)

See Also:


Attachments
extension of JUnitLaunchShortcut (20.27 KB, application/x-zip-compressed)
2014-05-05 07:13 EDT, Tobias Melcher CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Melcher CLA 2014-05-05 07:12:17 EDT
Hi colleagues,

it is currently not possible to execute single test methods of a test class which is parameterized (and contains "@RunWith(Parameterized.class)" annotation).

The JUnit result view shows message "Unrooted tests->initializationError". Reason is that the test requires a parameter value. 

If test is executed on class level everything is working fine and all tests with all parameter combinations are executed. If I have a failing test, I only want to launch a single test method what is currently not possible.

Similar discussion can be found here: http://stackoverflow.com/questions/16517300/junit-parameterized-tests-how-do-i-run-only-1-specific-test-from-intellij-eclip


Here a sample code to reproduce the problem:
package com.sap.adt.cds.ddl.internal.parser.versions.v1;

import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
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 MyParameterizedUnitTest {

	private final String value;

	public MyParameterizedUnitTest(String name, String value) {
		this.value = value;
	}

	@Parameters(name = "{0}")
	public static List<Object[]> parserVersions() throws Exception {
		return Arrays.asList(new Object[][] {//
				{ "v1", "paramValue1" }, //
						{ "v2", "paramValue2" }, //
						{ "v3", "paramValue3" } //
				});
	}

	@Test
	public void test1() {
		Assert.assertTrue(this.value, true);
	}

	@Test
	public void test2() {
		Assert.assertTrue(this.value, true);
	}

	@Test
	public void test3() {
		Assert.assertTrue(this.value, true);
	}

	@Test
	public void test4() {
		Assert.assertTrue(this.value, true);
	}
}

Trigger java editor context menu "Run AS->JUnit test" on class level and all tests are executed. Trigger test on method level by selecting "method1" does not work.

Please find attached a simple plugin containing an extension to the JUnit Run As context menu, which allows to trigger a simple test method of a prameterized junit test. Take a look into class JUnitParamLaunchShortcut which is a copy of JUnitLaunchShortcut with an additional method selectParamWithUi which allows to specifiy the paramValue via a simple dialog. The launch config is the modified so that test method is found and executed.

Maybe it makes sense to introduce this logic into the JUnitLaunchShortcut class. The logic of showing the dialog should then be only done when the test class contains the @RunWith(Parameterized.class) annotation.

This could be easily done from my point of view. Please let me know if you are interested; I am willing to help.

With best regards,
Tobias
Comment 1 Tobias Melcher CLA 2014-05-05 07:13:21 EDT
Created attachment 242700 [details]
extension of JUnitLaunchShortcut
Comment 2 Martin Mathew CLA 2014-05-12 02:07:59 EDT
The result when the test class is executed and when the test method is executed independently should be the same. Hence instead of contributing the new dialog to accept parameter value, the test method should read the parameters defined and execute the method accordingly.

@Markus: Kindly share your thoughts.

Yes, we welcome good quality patch. Refer https://wiki.eclipse.org/JDT_UI/How_to_Contribute to learn how to contribute a patch and to understand our coding guidelines.
Comment 3 Moritz Eysholdt CLA 2014-09-08 09:34:46 EDT
see also bug 443498
Comment 4 Noopur Gupta CLA 2014-10-13 09:36:33 EDT
*** Bug 446852 has been marked as a duplicate of this bug. ***
Comment 5 Moritz Eysholdt CLA 2014-10-13 09:42:36 EDT
The contribution made in bug 443498 fixe this issue.
Comment 6 Dani Megert CLA 2014-11-04 10:04:38 EST

*** This bug has been marked as a duplicate of bug 443498 ***