Hi,

1. I think the proper way is separating the test from
QuestionServiceImpl.

2. For testing QuestionServiceImpl, you should run two separate parts:
server side and client side.
a) In your case, there are no special in the server side.
b) In the client side, you can use GWTTestcase. Your test logic is on
the client side.
However, testing with GWTTestcase are slow. SyncProxy can be used on
the client side to invoke your remote service.
See http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/
and 
http://www.gdevelop.com/w/blog/2010/03/13/invoke-gwt-rpc-services-deployed-on-google-app-engine/
for how to use SyncProxy.



On Mar 14, 8:34 pm, Christian Schuhegger
<christian.schuheg...@gmail.com> wrote:
> Hello,
>
> I am doing experiments with a simple service QuestionService and I
> have a GWTTestCase that calls the QuestionService. All works fine, but
> my problem is that in the QuestionServiceImpl constructor I have to
> use the LocalServiceTestHelper helper infrastructure in order to make
> the whole test case work.
>
> My problem is now that I have to introduce dependencies in my
> QuestionServiceImpl on the appengine-testing jar in order to make my
> GWTTestCase work! My initial tries were to use the
> LocalServiceTestHelper directly in the gwtSetUp and gwtTearDown
> methods of the GWTTestCase but that does of course not work, because
> those classes are not compatible with the GWT (they obviously cannot
> and should not be compiled to java script).
>
> Is there any good way around this that I have to introduce a
> dependency on the appengine-testing infrastructure in my service
> implementation? Can I somehow detect that I am running in a
> GWTTestCase, then I could at least create a if-then-else block that
> only instantiates the helper in test mode.
>
> Many thanks for any recommendations!
>
> @RemoteServiceRelativePath("question")
> public interface QuestionService extends RemoteService {
>         public QuestionDefinition createQuestionDefinition(String question);
>         public void deleteQuestionDefinition(QuestionDefinition qd);
>         public QuestionDefinition findQuestionDefinitionById(String key);
>
> }
>
> public class QuestionServiceImpl extends RemoteServiceServlet
> implements QuestionService {
>
>         private final LocalServiceTestHelper helper = new
> LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
>
>         public QuestionServiceImpl() {
>                 super();
>                 helper.setUp();
>         }
>
>         public QuestionDefinition createQuestionDefinition(String question) {
>                 PersistenceManager pm = PMF.get().getPersistenceManager();
>                 QuestionDefinition qd = new QuestionDefinition(question);
>                 try {
>                         pm.makePersistent(qd);
>                 } finally {
>                         pm.close();
>                 }
>                 return qd;
>         }
>   ...
>
> }
>
> public class GwtTestQuestionService extends GWTTestCase {
>
>         @Override
>         public String getModuleName() {
>                 return "questionservice";
>         }
>
>         public void testQuestionServiceCreate() {
>                 QuestionServiceAsync questionService =
> GWT.create(QuestionService.class);
>
>                 String question = "Are you happy?";
>
>                 questionService.createQuestionDefinition(question,
>                                 new AsyncCallback<QuestionDefinition>() {
>                                         public void onFailure(Throwable 
> caught) {
>                                                 Assert.fail();
>                                                 finishTest();
>                                         }
>
>                                         public void 
> onSuccess(QuestionDefinition result) {
>                                                 Assert.assertNotNull(result);
>                                                 finishTest();
>                                         }
>                                 });
>         delayTestFinish(5000);
>         }
>
> }

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to