Wednesday, September 12, 2012

Running Liferay Unit and Integration Tests


Liferay source code contains many JUnit and Integration tests. It wasn't easy to setup my environment to run the tests so here is little guide for those how want to try it too.

Basic info is at http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+Testing+Infrastructure

I have Liferay sources in /opt/liferay.git/portal, let's call this directory SRC_ROOT for now.

Prerequisites:
* I have MySQL installed and run with Ubuntu defaults (at localhost, user root, empty password)
* Download run-tests.sh from https://gist.github.com/3706003
* Save it into SRC_ROOT
* Change permissions of the script file: chmod u+x run-tests.sh
* Note: I don't have any extra settings in any *.properties file

Running:
* Execute ./run-tests.sh inside SRC_ROOT
* Wait, it takes minutes to finish
* Ignore any exceptions during the tests, the important ones will be shown at the end
* At the end you should see

BUILD SUCCESSFUL
Total time: 6 minutes 42 seconds

**************************************
*           FOUND ERRORS             *
**************************************

./portal-impl/test-results/integration/TEST-com.liferay.portlet.wiki.trash.WikiNodeTrashHandlerTest.xml:    <error message="No AssetEntry exists with the key {classNameId=10149, classPK=18905}" type="com.liferay.portlet.asset.NoSuchEntryException">com.liferay.portlet.asset.NoSuchEntryException: No AssetEntry exists with the key {classNameId=10149, classPK=18905}
./portal-impl/test-results/integration/TEST-com.liferay.portlet.wiki.trash.WikiNodeTrashHandlerTest.xml:    <error message="No AssetEntry exists with the key {classNameId=10149, classPK=18910}" type="com.liferay.portlet.asset.NoSuchEntryException">com.liferay.portlet.asset.NoSuchEntryException: No AssetEntry exists with the key {classNameId=10149, classPK=18910}
./portal-impl/test-results/integration/TEST-com.liferay.portlet.wiki.trash.WikiNodeTrashHandlerTest.xml:    <error message="No AssetEntry exists with the key {classNameId=10149, classPK=18915}" type="com.liferay.portlet.asset.NoSuchEntryException">com.liferay.portlet.asset.NoSuchEntryException: No AssetEntry exists with the key {classNameId=10149, classPK=18915}
./portal-impl/test-results/integration/TEST-com.liferay.portlet.wiki.trash.WikiPageTrashHandlerTest.xml:    <error message="No WikiNode exists with the primary key 19001" type="com.liferay.portlet.wiki.NoSuchNodeException">com.liferay.portlet.wiki.NoSuchNodeException: No WikiNode exists with the primary key 19001
./portal-impl/test-results/integration/TEST-com.liferay.portlet.wiki.trash.WikiPageTrashHandlerTest.xml:    <error message="No WikiNode exists with the primary key 19006" type="com.liferay.portlet.wiki.NoSuchNodeException">com.liferay.portlet.wiki.NoSuchNodeException: No WikiNode exists with the primary key 19006
./portal-impl/test-results/integration/TEST-com.liferay.portlet.wiki.trash.WikiPageTrashHandlerTest.xml:    <error message="No WikiNode exists with the primary key 19011" type="com.liferay.portlet.wiki.NoSuchNodeException">com.liferay.portlet.wiki.NoSuchNodeException: No WikiNode exists with the primary key 19011


******************************************
* FOUND TEST FAILURES *
******************************************

./portal-impl/test-results/integration/TEST-com.liferay.portal.staging.StagingImplTest.xml:    <failure message="expected:&lt;Title[]en_US&gt; but was:&lt;Title[2]en_US&gt;" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError: expected:&lt;Title[]en_US&gt; but was:&lt;Title[2]en_US&gt;

Which means success! :)

Monday, September 10, 2012

When was a line added to a file - git bisect + grep

When do you want to know in which commit was a text added into a file, here are steps for bash + grep + git

export TEXT_TO_SEARCH="jcr.fetch.delay"
export FILE="portal-impl/src/portal.properties"

git bisect start "$FILE"
git bisect bad
git bisect good `git rev-list --parents HEAD "$FILE" | egrep "^[a-f0-9]{40}$"`

while
    ((grep "$TEXT_TO_SEARCH" "$FILE" > /dev/null && git bisect bad) || git bisect good) | grep Bisecting
do
    continue
done

git bisect visualize

git bisect reset