This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. Eclipse Running Liferay tests
Introduction #
This article discusses how to run automated Liferay tests from within Eclipse's JUnit runner.
Before you start #
If you haven't already:
Configure Eclipse to work with Liferay, as described here: Eclipse
Run the Liferay JUnit test suites (unit and integration) from the command line at least once, as described here: Liferay Testing Infrastructure (sections: "Initial Configuration", "Running the tests")
Specifically, run the test you want from the command line at least once:
ant test-class -Djunit.halt.on.failure=true -Dtest.class=DynamicDataSourceAdviceTest
If the test passes at the command line, it should pass within Eclipse.
Run a single unit test class #
ArrayUtilTest
Right-click, "Debug as JUnit Test"
Expected: Green bar in less than 1 second.
Run a single integration test class #
USAPhoneNumberFormatImplTest
Right-click, "Debug as JUnit Test"
Expected:
java.lang.ExceptionInInitializerError at com.liferay.portal.util.InitUtil.initWithSpringAndModuleFramework(InitUtil.java:235) at com.liferay.portal.util.InitUtil.initWithSpringAndModuleFramework(InitUtil.java:208) at com.liferay.portal.test.LiferayIntegrationJUnitTestRunner.initApplicationContext(LiferayIntegrationJUnitTestRunner.java:46)
Menu "Run", "Debug configurations..."
Select the launch configuration with the same name as the test class.
Tab: "Arguments"
Field: "VM arguments"
-Xmx256m -XX:MaxPermSize=256m -Dexternal-properties=portal-test.properties
Tab: "Classpath"
On the tree, click "User Entries"
Button: "Advanced...", "Add Folders"
Add the folder:
portal-master/portal-impl/test-classes/integration
("portal-test-ext.properties" is now on the classpath)
On the tree, click "User Entries"
Button: "Advanced...", "Add Folders"
Add the folder:
portal-master/portal-impl/classes
("jars.txt" is now on the classpath)
Make sure your portal-ext.properties file contains the entry:
liferay.home=<<your_bundles_directory_here>>
("osgi" directory is now visible)
Run the test again.
Expected: Green bar in 20 seconds.
PACL integration test #
AWTPermissionTest
Follow the integration test instructions above.
Right-click, "Debug as JUnit Test"
Expected:
java.lang.AssertionError at org.junit.Assert.fail(Assert.java:86) at org.junit.Assert.fail(Assert.java:95) at com.liferay.portal.security.pacl.test.AWTPermissionTest.test1(AWTPermissionTest.java:51)
Menu "Run", "Debug configurations..."
Select the launch configuration with the same name as the test class.
Tab: "Arguments"
Field: "VM arguments"
Append to the existing arguments that you had configured for the integration test:
-Djava.security.manager
-Djava.security.policy=${project_loc:portal-master}/portal-impl/test-classes/integration/com/liferay/portal/security/pacl/security.policyRun the test again.
Expected: Green bar in 35 seconds.
Cobertura unit test #
DynamicDataSourceAdviceTest
Right-click, "Debug as JUnit Test"
Expected:
java.lang.ExceptionInInitializerError at com.liferay.portal.kernel.test.CodeCoverageAssertor.<clinit>(CodeCoverageAssertor.java:174) at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceAdviceTest.<clinit>(DynamicDataSourceAdviceTest.java:54) Caused by: java.lang.ClassNotFoundException: com.liferay.cobertura.instrument.InstrumentationAgent at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
Menu "Run", "Debug configurations..."
Select the launch configuration with the same name as the test class.
Tab: "Arguments"
Field: "VM arguments"
-Dnet.sourceforge.cobertura.datafile=${project_loc:portal-master}/portal-impl/test-coverage/unit/cobertura.serTab: "Classpath"
On the tree, click "User Entries"
Button: "Add JARs..."
Add the JAR:
/portal-master/tools/cobertura-agent/cobertura-agent.jar
Run the test again.
Expected: Green bar in less than 1 second.
Notes #
If for any reason you modify "portal-test-ext.properties", you will need to switch to the command line and run "ant compile-test" again. This will copy the file to "portal-impl/test-classes/integration". (The Eclipse project won't do it automatically.)