I'm trying to implement the GWTTestCase approach for a couple of
scenarios and have serious doubts that I'm doing thing the 'right'
way, so help me out here ;-)
1. To get the test classes which extend GWTTestCase compiled I needed
to add <inherits name="com.google.gwt.junit.JUnit"/> to the .gwt.xml
file, is this the correct way because I couldn't find that on the
site. Secondly I'm adding this to my root .gwt.xml file of my GWT
application, is this correct or should I make a new .gwt.xml file to
serves as the root of my test package and which will inherit my
application root module?
2 Scenario 1: Testing a client side view model (pojo) + property
change support
public void testSearchCriteriaPropertyChange() {
delayTestFinish(10000);
final String SEARCH_CRITERIA = "testString";
final SearchModel model = new SearchModel();
model.addPropertyChangeListener("searchCriteria", new
PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
String searchCriteria = (String) event.getNewValue();
assertEquals(SEARCH_CRITERIA, searchCriteria);
finishTest();
}
});
model.setSearchCriteria(SEARCH_CRITERIA);
}
With the example above I have the following doubts:
- Why must I extend from the GWTTestCase when testing a simple pojo,
do I really need the extra overhead of booting up the shell? Can't I
just extend from JUnit TestCase instead? Perhaps some explanation on
when to use the GWTTestCase would be great (scenarios)!
2. Scenario 2: Testing GWT RPC
public void findMatches() {
delayTestFinish(10000);
SearchGWTService.App.getInstance().getMatches("dook", new
AsyncCallback() {
public void onFailure(Throwable cause) {
fail(cause.getMessage());
}
public void onSuccess(Object result) {
List matches = (ArrayList) result;
finishTest();
}
});
}
Doubts:
- My SearchGWTService implementation on the server-side is a Spring
bean, and it is also depending on multiple other beans. It is possible
to test a GWT RPC call in isolation or doesn't that make sense?
Mocking?
- Because my service implementation is a Spring bean, the Spring
container has to be booted on startup. I use for this a tomcat
instance which get started and during development I link my shell to
the tomcat instance. So now I'm in trouble because when I'm starting
the test case, the shell gets booted but he is using the internal
tomcat I guess which causes my test to fail because he can't find the
mapped service url on the server-side ... well duhh because it only
exists in my tomcat (with loaded spring ctx) application :-)
So ... at the end ... I'm really in doubt on what to test with GWT, is
there a lot I can unit test or is it mostly integration testing, like
the rpc stuff?
Help ... ;-)
Grtz
M.
Hi Maarten,
this post might be interesting for you:
I’m no expert with the GWTTestCase and unfortunatly I’m not using it too much as I would like (especially because it takes quite a while to run each test), but I’ll try to answer your questions.
Especially I found that you really don’t need a gwt.xml file for your test cases which declares and EntryPoint, as you just might want to test a method of a UI class.
And it makes a lot of sense to have multiple gwt.xml files for different TestCases, so that you can specify a source path which doesn’t have to be all of /client, but if you just
Are testing the package client.ui.table it might make sense to only add that to the source path of your module. (so that the compilation is done more rapidly)
Scenario 2: If you’re using Spring you might want to have a look at AbstractDependencyInjectionSpringContextTests.
This makes integration tests really simple and you don’t have to use GWTTestCase either. As you might read in the post above
The GWTTestCase is started with an internal Tomcat so that you can’t use an external server.
As mentioned above, currently I’m only using GWTTestCase for client UI classes which are using GWT code.
But even then not too much because of the long startup time it infers to compile the GWT code and execute the tests.
Perhaps others might chime in here and give there two cents too.
Dominik
<br
1. To get the test classes which extend GWTTestCase compiled I needed
to add <inherits name=" com.google.gwt.junit.JUnit"/> to the .gwt.xml
file, is this the correct way because I couldn't find that on the
site.
- Why must I extend from the GWTTestCase when testing a simple pojo,
do I really need the extra overhead of booting up the shell? Can't I
just extend from JUnit TestCase instead? Perhaps some explanation on
when to use the GWTTestCase would be great (scenarios)!
- My SearchGWTService implementation on the server-side is a Spring
bean, and it is also depending on multiple other beans. It is possible
to test a GWT RPC call in isolation or doesn't that make sense?
Mocking?
- Because my service implementation is a Spring bean, the Spring
container has to be booted on startup. I use for this a tomcat
instance which get started and during development I link my shell to
the tomcat instance.
So ... at the end ... I'm really in doubt on what to test with GWT, is
there a lot I can unit test or is it mostly integration testing, like
the rpc stuff?