Junit testing in Liferay 6.2 for custom portlets(service portlets)

Ganesh Puli, modified 6 Years ago. New Member Posts: 19 Join Date: 2/27/18 Recent Posts
Hi please suggest me in writing the unit testcases(mocking of Objects for the services) for the custom portlet, which has the dependency with other service portlet in liferay 6.2(please give the clarity with the full pledged example), which uses junit and mockito...

​​​​​​​Thanks
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Ganesh Puli
...(please give the clarity with the full pledged example)...
this might take a couple of weeks, especially given that we know nothing other than "everything is custom"...

Apart from that I'd say: Extract all the unit-testable code out of your portlet, so that the portlet remains a bit of the UI-layer that's largely wiring and can be reviewed. Unit-Test the heck out of the extracted code. Have your business code behind the service layer, again: Extract the testable code and behavior, to make it as independent of the persistence layer as possible. Then test the extracted code.

Reduce the code that you currently intend to mock. Turn it down to wiring the components to the APIs used. Unit testing a portlet is inherently hard, as it's on the UI layer - and unit testing UI is hard. I've not seen a lot of cases where mocking helped a great deal other than approving the implementation didn't change (but not any correctness).