Last Updated: July 19, 2016
·
766
· adamyin

Create first unit test with Arquillian

Required environment:
Maven
Netbeans

Step 1 – Create a new Maven project in Netbeans

Name: ArquillianDemo1
Add Maven Compiler Plugin
Add the Arquillian APIs in the pom.xml file.

<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.11.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

The Arquillian JUnit integration artifact also adds the Arquillian Core and ShrinkWrap APIs to the test classpath.
Optional (but recommanded): Upgrade the Maven Surefire Plugin from the default version.

Step2 – Create a new Java class named “Greeter” in the com.adam.arquilliandemo1.example package, with below code:

package com.adam.arquilliandemo1.example;

import java.io.PrintStream;

public class Greeter {

public void greet(PrintStream to, String name) {
    to.println(createGreeing(name));

}

private String createGreeing(String name) {
    return "Hello, " + name + "!";
}

}