JBoss.orgCommunity Documentation
The performance extension to Arquillian is a simple way of checking that the code you want to test performs within the range you want it to. It's can also automatically catch any performance regressions that might be added to your applications. - and as Arquillian itself, its very easy to use.
// include other arquillian imports here...
import org.jboss.arquillian.performance.annotation.Performance;
import org.jboss.arquillian.performance.annotation.PerformanceTest;
@PerformanceTest(resultsThreshold=2)
@RunWith(Arquillian.class)
public class WorkHardCdiTestCase
{
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class ,"test.jar")
.addPackage( WorkHard.class.getPackage())
.addManifestResource(
new ByteArrayAsset("".getBytes()),
ArchivePaths.create("beans.xml"));
}
@Inject HardWorker worker;
@Test
@Performance(time=20)
public void doHardWork() throws Exception
{
Assert.assertEquals(21, worker.workingHard(), 0d);
}
}
As you can see the only two additions needed are @Performance
and
@PerformanceTest
. They do different things and can be used seperately or combined.
@Performance
require one argument, time
(a double) which set the required maximum time that the test is allowed to spend in milliseconds. If the test exceeds that time it will fail with an exception explaining the cause.
@PerformanceTest
will cause every testrun of that test to be saved and every new run will compare results with previous runs. If the new testrun exceeds the previous runs with a defined threshold an exception will be thrown. The threshold can be set with the parameter resultsThreshold
. It is by default set to 1d.
How threshold is calculated: resultsThreshold * newTime < oldTime
.
The only extra dependency needed is to add arquillian-performance
to your pom.xml. Take a look at the Chapter 3, Getting started to see how you set up arquillian using maven.
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-performance</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
The JSFUnit integration to Arquillian is a simpler way of using JSFUnit.
You no longer need to manually post processor your WebArchives with JSFUnit dependecies
You can easly test single pages
Both in-contianer and client mode support
Use JUnit 4.8.1 or TestNG 5.12.1
JSFUnit integration requires a Java EE 6 compliant server. The packaging is based on web-fragments from Servlet 3.0.
// imports here...
@RunWith(Arquillian.class)
public class JSFUnitTestCase
{
@Deployment
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class ,"test.war")
.addClasses(
RequestScopeBean.class,
ScopeAwareBean.class)
.setWebXML("jsf/jsf-web.xml")
.addResource("jsf/index.xhtml", "index.xhtml")
.addWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
}
@Test
public void shouldExecutePage() throws Exception
{
JSFSession jsfSession = new JSFSession("/index.jsf");
Assert.assertTrue(Environment.is12Compatible());
Assert.assertTrue(Environment.is20Compatible());
Assert.assertEquals(2, Environment.getJSFMajorVersion());
Assert.assertEquals(0, Environment.getJSFMinorVersion());
JSFServerSession server = jsfSession.getJSFServerSession();
Assert.assertEquals("request", server.getManagedBeanValue("#{requestBean.scope}"));
}
}
The only dependencies needed is to add org.jboss.arquillian.framework:arquillian-framework-jsfunit
and org.jboss.jsfunit:jboss-jsfunit-core
to your pom.xml.
The rest is handled by Arquillian in the background.
Take a look at the Chapter 3, Getting started to see how you set up arquillian using maven.
<dependency>
<groupId>org.jboss.arquillian.framework</groupId>
<artifactId>arquillian-framework-jsfunit</artifactId>
<version>1.0.0.Alpha4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.jsfunit</groupId>
<artifactId>jboss-jsfunit-core</artifactId>
<version>1.3.0.Final</version>
<scope>test</scope>
</dependency>
To use JSFUnit with Arquillian, JSFUnit 1.3.0.Final is required.