JBoss Community Archive (Read Only)

Arquillian Old

Introductory examples

The following examples demonstrate the use of Arquillian. Currently Arquillian is distributed as a Maven only project, so you'll need to grab the examples from Git. You can choose between a JUnit example and a TestNG example. In this tutorial we show you how to use both.

git clone git://github.com/arquillian/arquillian.git arquillian
cd arquillian
git checkout 1.0.0-SNAPSHOT

If you want to try the JUnit examples do:

cd examples/junit

Or if you want to try the TestNG examples do:

cd examples/testng

Running these tests from the command line is easy. The examples run against all the servers supported by Arquillian (of course, you must choose a container that is capable of deploying EJBs for these tests). To run the test, we'll use Maven. For this tutorial, we'll use JBoss AS 6 (currently at Milestone 3), for which we use the jbossas-remote-6 profile.

First, make sure you have a copy of JBoss AS; you can download it from jboss.org. We strongly recommend you use a clean copy of JBoss AS. Unzip JBoss AS to a directory of your choice and start it; we'll use $JBOSS_HOME to refer to this location throughout the tutorial.

$ unzip jboss-6.0.0.Final.zip && mv jboss-6.0.0.Final $JBOSS_HOME && $JBOSS_HOME/bin/run.sh

Now, we tell Maven to run the tests, for both JUnit and TestNG:

$ mvn test -Pjbossas-remote-6

$ cd ../arquillian-example-junit/
$ mvn test -Pjbossas-remote-6

You can also run the tests in an IDE. We'll show you how to run the tests in Eclipse, with m2eclipse installed, next.

Before running an Arquillian test in Eclipse, you must have the plugin for the unit testing framework you are using installed. Eclipse ships with the JUnit plugin, so you are already setup if you selected JUnit. If you are writing your tests with TestNG, you need the Eclipse TestNG plugin.

Since the examples in this guide are based on a Maven 2 project, you will also need the m2eclipse plugin. Instructions for using the m2eclipse update site to add the m2eclipse plugin to Eclipse are provided on the m2eclipse home page. For more, read the m2eclipse reference guide.

Once the plugins are installed, import your Maven project into the Eclipse workspace. Before executing the test, you need to enable the profile for the target container, as we did on the command line. We'll go ahead and activate the profile globally for the project (we also need the default profile, read the note above for more). Right click on the project and select Properties. Select the Maven property sheet and in the first form field, enter jbossas-remote-6; you also need to tell Maven to not resolve dependencies from the workspace (this interferes with resource loading):

images/author/download/attachments/23822351/maven-properties-screen.png
Maven settings for project

Click OK and accept the project changes. Before we execute tests, make sure that Eclipse has properly processed all the resource files by running a full build on the project by selecting Clean from Project menu. Now you are ready to execute tests.

Assuming you have JBoss AS started from running the tests on the command line, you can now execute the tests. Right click on the InjectionTestCase.java file in the Package Explorer and select Run As... > JUnit Test or Run As... > TestNG Test depending on which unit testing framework the test is using.

images/author/download/attachments/23822351/testng-run-test.png
Running the test from Eclipse using TestNG

You can now execute all the tests from Eclipse!

That should give you a taste of what Arquillian tests look like. To learn how to setup Arquillian in your application and start developing tests with it, refer to the Getting started chapter.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:18:46 UTC, last content change 2011-04-16 15:26:05 UTC.