Reputation: 60213
I wrote a Liferay service.
It does complex things with many different expected outputs depending on the inputs. I want to test the outputs with all of these inputs.
My service is used by several portlets, so I could manually test using the portlets, but it would take several days to test all situations, and I have to do that every week. Moreover, some inputs are not reachable using the current portlets.
In the implementation module of my service, I created JUnit tests, but they fail because they can not find OSGi classes:
Now I realize that a Liferay service can not really live on its own without the OSGi+Liferay infrastructure to support it behind, give it access to other services and data.
So, I am OK with running my tests within a live Liferay instance rather than in Eclipse. I am OK with my unit tests being launched by a Gogo Shell command, a REST call, an ad-hoc portlet, or even on module activation.
Question: How to implement such "unit" tests for my Liferay service?
Note: Unit tests for Liferay portlets are covered by another question.
Upvotes: 2
Views: 944
Reputation: 19606
I am not a liferay expert but I can describe the general approach for such tests. You need these steps:
As liferay is an OSGi system possibly the integration step will happen after liferay is started by uploading your bundles.
This might be helpful:
If you can start liferay as a docker image then the TestContainers project might be helpful. It takes care of starting and stopping docker containers from java junit code in a safe way. For example it makes sure the containers are always cleaned up in the end even if your test crashes.
Upvotes: 2