Liferay - testing a portlet
While trying to find out how to test a MVC liferay portlet, I realised that there is not much of documentation about the subject. A typical liferay project has some predefined ant targets in the build.xml file about tests, but there is no hint how to make your make run with them.
After looking at the scripts more carefully, I found out that the testing code should simply "live" in a test directory in the same level with the docroot directory. This has the effect, that the testing code will not be part of the war file.
In the test directory you have to put your unit testing files in a unit subdirectory and your integration tests in an integration subdirectory.
So, the project in the file system should look like this:
+-- unit // put here your unit test
+-- integration // put here your integration tests
Keeping your testing code outside the docroot directory makes a nice clean war file, without any tests inside.
The name of your test classes should end with Test, for example SampleTest.
Having the above setup, you can run your tests with the "test" ant target of the build.xml file in your project. This is a nice way to run the tests with a CI tool.
More posts about testing portlets with liferay will follow... ;)