Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-clicking Spock def name in JUnit results view fails to recognize the method name #115

Closed
davidmichaelkarr opened this issue Apr 10, 2015 · 3 comments

Comments

@davidmichaelkarr
Copy link

When I run Java unit tests, I can double-click an entry from the "Junit" results view to go to the test method represented in the results view.

However, when the test is based on Spock, which I assume would be handled by this plugin, it appears the algorithm used to determine the method name is not "Groovy-able". It appears that it only takes the first word of the method name, and stops at the first space. Groovy method names can be quoted strings with spaces, which is what is typically done with Spock spec methods. The result is an error dialog which says "Method 'xxx' not found. Opening the test class.".

@jespersm
Copy link

This error comes from Eclipse JDT's JUnit support itself.
The problem could be fixable by Eclipse, for methods like def "test that blah"() since it assumes that test methods meet Java naming standards. Perhaps that's where we should be reporting this.

However, for tests using @unroll with string formats, the issue can't really be fixed since the testcase method's name is not reported in the JUnit results, only the testcase's name.

@apupier
Copy link

apupier commented Nov 30, 2015

The issue on JDT side is reported here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=343129

Help is welcome to fix the issue.

@eric-milles
Copy link
Member

The problem starts in OpenTestAction, which truncates method name before first non-identifier character. You will need to follow up with the JDT bug to get resolution.

	private static String extractRealMethodName(TestCaseElement testCase) {
		//workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=334864 :
		if (testCase.isIgnored() && JavaConventions.validateJavaTypeName(testCase.getTestName(), JavaCore.VERSION_1_5, JavaCore.VERSION_1_5).getSeverity() != IStatus.ERROR) {
			return null;
		}
		
		//workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=275308 :
		String testMethodName= testCase.getTestMethodName();
		for (int i= 0; i < testMethodName.length(); i++) {
			if (!Character.isJavaIdentifierPart(testMethodName.charAt(i))) {
				return testMethodName.substring(0, i);
			}
		}
		return testMethodName;
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants