Take the 2-minute tour ×

I want to preform a JUnit tests on my application. I've never done JUnit testing before so I have a couple of (maybe trivial) questions:

  1. Where should I put a test class? I came across with this thread: Where should I put my JUnit tests?, and the guy that answers the question is referring to maven projects, but I don't use maven. He explains (in the thread I linked above) that he puts the test class in a different location but in the same package. How can it be done in a GWT project?

  2. How should I execute these tests once they are ready (where in the code to put the execution)?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You should begin by reviewing this: Unit Testing GWT Applications with JUnit.

  1. The other thread is good and reflects the typical JUnit practice, and isn't specific to maven: use a mirror of your package tree under a directory called test. So for instance if your GWT EntryPoint module is located in this directory structure:


    Then your test code will be here:


    If you've created your GWT project using webAppCreator then you should already have a test directory containing the package structure as described.

  2. If you use webAppCreator to create your project, the project can be created with unit testing built-in like so:

    webAppCreator -junit -out MyProject com.myproject.mypackage.MyEntryPoint

    This will create a test target. If you're using Eclipse, then you should have a Run selection for: Run As -> GWT Unit Test for running your tests.

    If you're using ant instead of Eclipse then this should run your unit tests:

    ant test

    If you didn't use -junit to create the project, the test targets are typically still there, just commented out. Search junit in build.xml to find the targets, and un-comment them.

share|improve this answer
add comment

You need to take a look at this article, MVP1 and MVP2, these are a pattern designs used to Unit Test your application in pure java environment, because using GWT Test Case runs very slow the patterns also has many advantages like separate the logic from the view so you can change the view for Android, for example.

share|improve this answer
add comment

Your Answer


