Reputation: 988
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:
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?
How should I execute these tests once they are ready (where in the code to put the execution)?
Upvotes: 3
Views: 2257
Reputation: 18941
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.
Upvotes: 1
Reputation: 59607
You should begin by reviewing this: Unit Testing GWT Applications with JUnit.
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:
project/src/com/myproject/mypackage/MyEntryPoint.java
Then your test code will be here:
project/test/com/myproject/mypackage/MyEntryPointTests.java
If you've created your GWT project using webAppCreator
then you should already have a test
directory containing the package structure as described.
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.
Upvotes: 3