ABOUT US

|

SUPPORT

|

BLOGS

 

 

DEVELOPER BLOG

 

 

 

 

 

 

 

Setting up LiquidTest with Maven

 

Holly Irving

 

 

 

 

 

One of our Developers put together a nice Maven Integration document that will go out with our website refresh later this month.  Given the popularity of Maven, I thought I would share it before the site-refresh goes live!

Install Maven

This guide assumes you already have Java and Maven 2 installed. If you don’t have Maven, you can follow the installation instructions on the Maven website.

Open a command prompt with access to Maven so that you can follow the rest of the instructions in this guide.

Install LiquidTest into your local Maven repository

Maven projects cannot depend on JARs that are not Maven artifacts, which means that you can’t just drop LiquidTest into your classpath as you would with other build systems. Instead you’ll need to install LiquidTest into your local repository so that Maven can see it and your tests can depend on it.

Suppose you’ve obtained liquidtest-nodeps-1.0.17.jar and you’d like to tell Maven about it. Run the following command in the same directory as the JAR file:

$ mvn install:install-file \
      -Dfile=liquidtest-nodeps-1.0.17.jar \
      -DgroupId=local.jadeliquid.liquidtest \
      -DartifactId=liquidtest-nodeps \
      -Dversion=1.0.17 \
      -Dpackaging=jar

If you understand how to use private Maven repositories, you can manage your LiquidTest JARs centrally instead of installing them manually on each workstation/server.

Package and install you LiquidTest license key

LiquidTest looks for its license key and other configuration parameters in a liquidtest.properties file on its classpath. There are a few ways to achieve this, but one of the simplest is to add your configuration to its own JAR and install it into Maven’s local repository.

Start by creating your liquidtest.properties file. It should contain at least the following line:

licenseKey=<INSERT YOUR LIQUIDTEST LICENSE KEY HERE>

You can add other LiquidTest configuration properties if you like.

Be sure to use your actual license key instead of the placeholder, or LiquidTest won’t run!

Now, add your properties file to its own JAR archive with the following command:

$ jar -cvf liquidtest-properties.jar liquidtest.properties

The final step is to add this JAR to your repository as you did with LiquidTest itself:

$ mvn install:install-file \
      -Dfile=liquidtest-properties.jar \
      -DgroupId=local.jadeliquid.liquidtest \
      -DartifactId=liquidtest-properties \
      -Dversion=1.0-SNAPSHOT \
      -Dpackaging=jar

Create a Maven project

If you don’t already have a Maven project, you’ll need to create one by entering the following:

$ mvn archetype:create \
      -DgroupId=com.example.myproject \
      -DartifactId=my-project

This will create a skeleton project in the my-project/ directory. You can replace the group and artifact IDs with something more suitable for your project.

Add the FailSafe plugin for integration testing

The FailSafe plugin is used for integration testing in Maven. To use it, add the following to your project’s pom.xml:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>failsafe-maven-plugin</artifactId>
        <version>2.4.3-alpha-1</version>
        <executions>
          <execution>
            <id>integration-test</id>
            <goals>
              <goal>integration-test</goal>
            </goals>
          </execution>
          <execution>
            <id>verify</id>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

You can find more information on FailSafe at http://mojo.codehaus.org/failsafe-maven-plugin/usage.html.

Add LiquidTest dependencies

Add these dependencies to your project’s pom.xml so that the integration-test phase can use LiquidTest to run your tests:

<project>
  [...]
  <dependencies>
    [...]
    <dependency>
      <groupId>local.jadeliquid.liquidtest</groupId>
      <artifactId>liquidtest-nodeps</artifactId>
      <version>1.0.17</version>
      <scope>integration-test</scope>
    </dependency>
    <dependency>
      <groupId>local.jadeliquid.liquidtest</groupId>
      <artifactId>liquidtest-properties</artifactId>
      <version>1.0-SNAPSHOT</version>
      <scope>integration-test</scope>
    </dependency>
    [...]
  </dependencies>
  [...]
</project>

Update the JUnit dependency to JUnit 4

Maven’s default project configuration uses JUnit 3, which is no good if you’re using LiquidTest to generate JUnit 4 test files. Luckily this is easy to fix: find the JUnit <version>3.8.1</version> element in your pom.xml and replace the version number with a more suitable one. You can specify a particular version of JUnit with <version>4.3.1</version>, or request any version of JUnit 4 with <version>[4.0,)</version>.

You will also need to add JUnit to the integration-test lifecycle phase. To do this, replace <scope>test</scope> with <scope>test integration-test</scope>.

Here's how your project's <dependencies> configuration should appear after making these changes:

<project>
  [...]
  <dependencies>
    [...]
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>[4.0,)</version> <!-- version 4.0 or greater -->
      <scope>test integration-test</scope> <!-- needed by integration-test -->
    </dependency>
    [...]
  </dependencies>
  [...]

Enable support for Java 5 constructs

Maven uses Java 1.3 syntax by default, which is no good if you want to compile JUnit 4 tests with annotations. To remedy this, explicitly set the Java source and target versions in the compiler plugin's configuration using the following code:

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source> <!-- use Java 5 syntax -->
          <target>1.5</target> <!-- required for Java 5 syntax -->
        </configuration>
      </plugin>
      [...]
    </plugins>
    [...]
  </build>
  [...]
</project>

If you want to use Java 6 language features, you'll need to write <source>1.6</source> instead.

Add LiquidTest tests to your Maven tree

By default, FailSafe will look for test files using the pattern **/*IT.java. Create a test file with a name ending in IT and add it to your project's src/test/java/ tree at the appropriate package location.

For example, this test script would be placed at src/test/java/com/example/myproject/SampleIT.java:

package com.example.myproject;
 
import static org.junit.Assert.assertEquals;
 
import org.junit.Test;
import org.junit.runner.RunWith;
 
import com.jadeliquid.liquidtest.Browsers;
import com.jadeliquid.liquidtest.TestBrowser;
import com.jadeliquid.liquidtest.plugin.junit4.BrowserRunner;
 
@RunWith(BrowserRunner.class)
public class SampleIT
{
	public TestBrowser browser;
 
	@Test
	@Browsers("Firefox2.0")
	public void rfcHref()
	{
		browser.load("example.com");
		assertEquals("http://www.rfc-editor.org/rfc/rfc2606.txt",browser.getNodeAttribute("//*[text()='RFC \n  2606']", "href"));
	}
 
}

Run your tests in Maven

Now that everything is set up, you should be able to invoke Maven to run your LiquidTest integration tests:

$ cd my-project
$ mvn verify

Once Maven has downloaded any needed dependencies it will use LiquidTest to execute your tests. You should see summary results in your terminal, and detailed results should appear in the target/failsafe-reports/ directory in your Maven project tree.

 

 

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • DZone
  • TwitThis
  • email
 Comments (1)

 

 


 

 

Comments:

  1. Thanks alot – your answer solved all my problems after svereal days struggling

    Comment by Isabelle on June 12, 2011 at 10:11 pm

Add Comment..

 

 

About this blog..

 

This is an informal place for the team at JadeLiquid to discuss software, the rotation of the earth and other things usually discussed in the JadeLiquid corridors.

 

 

 

Subscribe: By Feed  By Email

 

 

 

 

 

Categories

 

 

JadeLiquid

LiquidTest

 

 

Software Testing

 

 

WebRenderer

 

 

 

 

Recent Posts

 

 

Selenium 2 / WebDriver support coming soon to LiquidTest..
Running Selenium Tests from the Command Line
LiquidTest 3.0 with Selenium support ships!
Setting up Atlassian Bamboo to run automated Web 2.0 tests
888 installer builds and 7469 code checkins later LiquidTest 2.0 ships!

 

 

 

 

 

Popular Posts

 

 

Testing complex Ajax content
Running Selenium Tests from the Command Line
Setting up LiquidTest with Subversion and Hudson (Continuous Integration) - part 1
Creating Data-Driven Functional Tests with LiquidTest
One tool to rule them all - Reducing team division
Setting up LiquidTest with Subversion and Hudson (Continuous Integration) part 2
Is manual testing crippling your development project?
Eclipse and LiquidTest UI Introduction
Protecting investment: Tests that do not break with page changes
Testing Dynamic Elements – Having a Plan B

 

 

 

 

 

Archives

 

 

May 2011 (2) April 2011 (1) November 2010 (2) March 2010 (1) February 2010 (1) November 2009 (1) October 2009 (1) September 2009 (2) August 2009 (1) July 2009 (1) June 2009 (1) April 2009 (1) March 2009 (1)

 

 

 

 

 
   News / Events

 

 > LiquidTest EOL Announcement - Info
 > LiquidTest Release 3.0! - Available
 > Visual Studio Plugin Released! - Release
 > Cruise Control .NET Integration - Info
 > Automate your Dev/Test Process - Webinar
 > Is manual testing crippling your project? - Blog
 > Testing complex Ajax content - Blog
 
 
   Recently Added Content  
 
 > Run LiquidTest's on Selenium RC/Server - Info
 > Setting up LiquidTest with Maven - Blog
 > Officially Supported Ajax Frameworks - Info
 > Atlassian Bamboo Integration - Tech
 > Setting up LiquidTest with SVN and Hudson - Blog
 > Creating Data-Driven Functional Tests - Blog
 > Reducing Test Maintenance - Blog
 
 
  Copyright JadeLiquid Software - 2014