Hi Konstantin,
Thanks for your reply.
I am trying to test only client side code in hosted mode, using Eclipse and Designer.
This seems to me to be the simplest first step, before
venturing into testing server-side communication.
So my example test class creates a button and does a couple of simple
JUnit assertions. I'll spell out what I do so you can see immediately
where I have gone wrong:
First of all, the EntryPoint classes is:
- Code: Select all
package au.gov.bom.aifs.webcam.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class DesignerJUnit implements EntryPoint {
private MyExtendedButton clickMeButton;
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
clickMeButton = new MyExtendedButton();
rootPanel.add(clickMeButton);
clickMeButton.setText("Click me!");
clickMeButton.setMyButtonData("SOME BUTTON DATA");
clickMeButton.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
MyExtendedButton myButton = (MyExtendedButton)sender;
Window.alert("Hello, GWT World!" + " and my data is: " + myButton.getMyButtonData());
}
});
}
}
It uses an extension of the Button class:
- Code: Select all
package au.gov.bom.aifs.webcam.client;
import com.google.gwt.user.client.ui.Button;
public class MyExtendedButton extends Button {
private String myButtonData;
public MyExtendedButton() {
}
/**
* @return the myButtonData
*/
public String getMyButtonData() {
return myButtonData;
}
/**
* @param myButtonData
* the myButtonData to set
*/
public void setMyButtonData(String myButtonData) {
this.myButtonData = myButtonData;
}
}
I created class MyExtendedButtonTest using the Eclipse New JUnit
Test Case menu option, and told it the Class under test is:
au.gov.bom.aifs.webcam.client.MyExtendedButton
and that its Superclass is:
GWTTestCase
I selected Test Methods for getMyButtonData() and the constructor.
I used Organize Imports to import the fully-qualified GWTTestCase class.
I used Quick Fix to add the unimplemented method getModuleName().
I modified getModuleName() to return the fully-qualified name of
the Module:
"au.gov.bom.aifs.webcam.client.DesignerJUnit"
I right-clicked in the Package Explorer on MyExtendedButtonTest.java
and invoked Run As | JUnit Test.
It failed, as we expected, with the GWTShell exception.
So far, so good.
The next step: Run | Open Run Dialogue | Classpath
Clicked on Bootstrap Entries
Clicked on Add External JARs and selected gwt-dev-windows.jar
Clicked on Apply then Run
java.lang.ExceptionInInitializerError
at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:194)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:114)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.NullPointerException
at com.google.gwt.util.tools.Utility.computeInstallationPath(Utility.java:282)
at com.google.gwt.util.tools.Utility.getInstallPath(Utility.java:223)
at com.google.gwt.util.tools.ToolBase.<clinit>(ToolBase.java:55)
... 15 more
That's may be what you expected, given that I haven't added the "src"
folder yet.
Next: Run | Open Run Dialogue | Classpath
Clicked on Bootstrap Entries
Then clicked on Advanced | Add Folders
Selected the DesignerJunit project.
Apply and Run
It fails with the following stack trace in the Eclipse Console:
java.lang.NoClassDefFoundError: com/google/gwt/junit/client/GWTTestCase
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClass0(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:425)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
The application compiles and runs correctly in hosted mode. There's no
problem there. It's getting JUnit working with GWT that's the problem.
Can you tell me where I have gone wrong, or what to do next?
Regards, Mal.