掲示板

Unit Test only possible for portal, not for portlets with services? {Solve

thumbnail
14年前 に Stef Heyenrath によって更新されました。

Unit Test only possible for portal, not for portlets with services? {Solve

Junior Member 投稿: 76 参加年月日: 08/12/03 最新の投稿
In the portal source code, there are several test classes. (portal-impl/test/com/liferay/counter/service/CounterServiceTest.java)

The most interesting class is : BaseTestCase.

In this class the environment is setup to make unit testing possible. (Spring beans are initialized and Jetty is started up.)
The method which does all the work is : InitUtil.initWithSpring().

I want to unit test the business logic from the services (classes created by the service-builder) from my portlet so that I don't need a fully working Liferay environment to test some small functionality.

The question is : How can I correctly initialize the spring beans from my own portlet ?
Because this is needed to solve the "BeanLocator is null" exception.
thumbnail
14年前 に Stef Heyenrath によって更新されました。

RE: Unit Testing only possible for portal, not for portlets with services?

Junior Member 投稿: 76 参加年月日: 08/12/03 最新の投稿
I found a solution!.
(It took a lot of searching + developing time to solve this issue, and as far as I know, this is the only solution present in the whole Liferay community!)

I did the following:

1. Create an own test project based on the portal-src from Liferay.
2. Remove all java files but keep all jar files.
3. Add portal-impl.jar, portal-kernel.jar, portal-service.jar and util-java.jar to this project.
4. Create an own version of initWithSpring() which initializes my portlet.
5. Update the build file from the services-portlet project to create a jar file which includes all classes + configuation files. (xml + properties)

See Services-Portlet project and the Test Services-Portlet project for more details.
14年前 に k. chandra sekhar によって更新されました。

RE: Unit Testing only possible for portal, not for portlets with services?

Regular Member 投稿: 149 参加年月日: 09/07/07 最新の投稿
Hi,

Can you please explain in detail what you have followed the approach.
Actually I want to increment the liferay counter value by using the myeclipse.

Thanks in advance

Regards,
K.chandra sekhar
thumbnail
13年前 に Laurent Gauthier によって更新されました。

RE: Unit Testing only possible for portal, not for portlets with services?

New Member 投稿: 15 参加年月日: 10/02/03 最新の投稿
For the benefits of those, who, like me, stumbled across the problem of unit testing Liferay portlets, I published a Blog article on the subject at: Liferay Portlet Unit testing.

It outlines a simple and effective solution to this problem. Feedback and comments are welcome.

Laurent