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)?
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 GWTEntryPointmodule is located in this directory structure:Then your test code will be here:
If you’ve created your GWT project using
webAppCreatorthen you should already have atestdirectory containing the package structure as described.If you use
webAppCreatorto create your project, the project can be created with unit testing built-in like so:This will create a
testtarget. If you’re using Eclipse, then you should have a Run selection for:Run As -> GWT Unit Testfor running your tests.If you’re using ant instead of Eclipse then this should run your unit tests:
If you didn’t use
-junitto create the project, the test targets are typically still there, just commented out. Searchjunitinbuild.xmlto find the targets, and un-comment them.