Today, I decided to run
EclEmma on the Groovy-
Eclipse plugin test suite. Shockingly, I found that JUnit support, content assist, and code navigation are completely test-fress. So, I took a stab at creating a solid and flexible test infrastructure that makes it easy to write plugin tests, especially ones that exercise the Java model.
How did I do this? I did it by hooking into existing JDT functionality, just like I have been doing for the rest of my work on Greclipse. I downloaded the JDT core tests from CVS and used what I needed. Now, I can write extremely concise tests that exercise the code I want it to. For example, I wrote the following test case that tests code selection on a closure in a groovy script (i.e., this is the code that is executed when you perform
Open Declaration in an editor):
public void testCodeSelectClosure() throws Exception {
IPath projectPath = createGenericProject();
IPath root = projectPath.append("src");
String contents =
"def x = {\n"+
"t -> print t\n"+
"}\n"+
"x('hello')\n";
env.addGroovyClass(root, "Script", contents);
GroovyCompilationUnit unit = getGroovyCompilationUnit(root, "Script.groovy");
IJavaElement[] elts = unit.codeSelect(contents.lastIndexOf('x'), 1);
assertEquals("Should have found a selection", 1, elts.length);
assertEquals("Should have found local variable 'x'", "x", elts[0].getElementName());
}
I have written many tests for JUnit support (or is that GUnit?), and some for code selection. I still need to work on content assist. So, I can now be confident that as we make changes towards the 2.0 release, we are not sliding back in functionality. There is a lot of good work that has already been put into the plugin (including groovy-aware type inference for content assist) and we need to make sure that this does not regress as we go forward.