Liferay - testing a portlet

Posted on 19/08/2013 by Charalampos Chrysikopoulos

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:
[cc]
project name
+-- docroot
+-- test
+-- unit // put here your unit test
+-- integration // put here your integration tests
build.xml
[/cc]

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... ;)

This entry was posted in Liferay, test and tagged integration-test, Liferay, test, unit-test by Charalampos Chrysikopoulos