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

Bug 368172

Summary: [JUnit] Running a single junit @Test annotated method with arguments does not provide a useful error
Product: [Eclipse Project] JDT Reporter: Michael Matczynski <mjm>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, daniel_megert, manju656
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Michael Matczynski CLA 2012-01-09 10:21:38 EST
Build Identifier: 20110916-0149

Trying to run a single JUnit method that incorrectly has an argument does not display any errors.

Reproducible: Always

Steps to Reproduce:
1. In a junit test class, define a test method with a disallowed argument like:
@Test
public void testSomething(int thisShouldNotBeHere) {}

2. Trying to test the entire class with Run->Run As->JUnit Test results in a useful message saying:
java.lang.Exception: Method testSomething should have no parameters
	at org.junit.internal.runners.MethodValidator.validateTestMethods(MethodValidator.java:80)
	at org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:28)
	at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:43)
	at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:36)
	at org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:27)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:76)
	at com.cloudswitch.tests.CSTestRunner.<init>(CSTestRunner.java:32)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


3. Trying to test the specific, invalid method by right-clicking in the Outline View and selecting Run As->JUnit Test results in no useful message.  There is no exception displayed, the JUnit View is unchanged, and the Debug View simply shows:
<terminated, exit value: 0>/opt/java/bin/java (Jan 9, 2012 10:17:17 AM)
Comment 1 Ayushman Jain CLA 2012-01-10 03:14:47 EST
Moving to JDT/UI.
Comment 2 Martin Mathew CLA 2014-04-08 22:13:57 EDT
Tested using Build id: I20140325-0830 and JUnit 4, individually executing the invalid test method shows the same error as when the entire test class is executed:

TestSomething.testSomething
Unrooted Tests
initializationError(p1.TestSomething)
java.lang.Exception: Method testSomething should have no parameters

	at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:72)

	at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:133)

The test code snippet used:
package p1;

import org.junit.Test;

public class TestSomething {

	@Test
	public void testSomething(int thisShouldNotBeHere) {
	}

}