« Voltar para Eclipse

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.policy

Run 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.ser

Tab: "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.)

See also #

Liferay Testing Infrastructure

JUnit

0 Anexos
27091 Visualizações
Média (0 Votos)
A média da avaliação é 0.0 estrelas de 5.
Comentários
Respostas do tópico Autor Data
Unable to run unit test it gives... Haris Ahmed 8 de Janeiro de 2015 05:57
I am facing above error when running unit test... Haris Ahmed 8 de Janeiro de 2015 06:25

Unable to run unit test it gives ClassNotFoundException

Class not found com.liferay.portal.kernel.util.ArrayUtilTest
java.lang.ClassNotFoundException: com.liferay.portal.kernel.util.ArrayUtilTest
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunne­r.java:685)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRun­ner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner­.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner­.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java­:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav­a:192)
Postado em 08/01/15 05:57.
I am facing above error when running unit test using eclipse.
Postado em 08/01/15 06:25.