Arquillian TestRunner Spock Example: Groovy 1.x

Examples of using Spock with Arquillian

License

License

Categories

Categories

Groovy Languages JBoss Container Application Servers Spock Application Testing & Monitoring Arquillian
GroupId

GroupId

org.jboss.arquillian.spock
ArtifactId

ArtifactId

arquillian-spock-example-groovy-1.x
Last Version

Last Version

1.0.0.Beta3
Release Date

Release Date

Type

Type

jar
Description

Description

Arquillian TestRunner Spock Example: Groovy 1.x
Examples of using Spock with Arquillian
Project URL

Project URL

http://arquillian.org

Download arquillian-spock-example-groovy-1.x

How to add to project

<!-- https://jarcasting.com/artifacts/org.jboss.arquillian.spock/arquillian-spock-example-groovy-1.x/ -->
<dependency>
    <groupId>org.jboss.arquillian.spock</groupId>
    <artifactId>arquillian-spock-example-groovy-1.x</artifactId>
    <version>1.0.0.Beta3</version>
</dependency>
// https://jarcasting.com/artifacts/org.jboss.arquillian.spock/arquillian-spock-example-groovy-1.x/
implementation 'org.jboss.arquillian.spock:arquillian-spock-example-groovy-1.x:1.0.0.Beta3'
// https://jarcasting.com/artifacts/org.jboss.arquillian.spock/arquillian-spock-example-groovy-1.x/
implementation ("org.jboss.arquillian.spock:arquillian-spock-example-groovy-1.x:1.0.0.Beta3")
'org.jboss.arquillian.spock:arquillian-spock-example-groovy-1.x:jar:1.0.0.Beta3'
<dependency org="org.jboss.arquillian.spock" name="arquillian-spock-example-groovy-1.x" rev="1.0.0.Beta3">
  <artifact name="arquillian-spock-example-groovy-1.x" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.jboss.arquillian.spock', module='arquillian-spock-example-groovy-1.x', version='1.0.0.Beta3')
)
libraryDependencies += "org.jboss.arquillian.spock" % "arquillian-spock-example-groovy-1.x" % "1.0.0.Beta3"
[org.jboss.arquillian.spock/arquillian-spock-example-groovy-1.x "1.0.0.Beta3"]

Dependencies

test (4)

Group / Artifact Type Version
org.jboss.arquillian.spock : arquillian-spock-container jar 1.0.0.Beta3
org.spockframework : spock-core jar 0.7-groovy-1.8
org.codehaus.groovy : groovy-all jar 1.8.9
junit : junit jar

Project Modules

There are no modules declared in this project.

Spock Arquillian Extension

BDD Testing in the container!

What is it?

Arquillian is testing framework, developed at JBoss.org, that empowers developers to write integration tests for business objects that are executed inside of an embedded or remote container--options include a servlet container, a Java EE application server or a Java SE CDI environment.

Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language. Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms.

The Spock Arquillian Extension opens up for the beauty of Spock tests running in-container using Arquillian with full EJB, Resource and CDI injection.

Example

 @Deployment
 def static JavaArchive "create deployment"() {
     return ShrinkWrap.create(JavaArchive.class)
             .addClasses(AccountService.class, Account.class, SecureAccountService.class)
             .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
 }
 
 @Inject 
 AccountService service
        
 def "transferring between accounts should result in account withdrawal and deposit"() {
      when:
      service.transfer(from, to, amount)
        
      then:
      from.balance == fromBalance
      to.balance == toBalance
        
      where:
      from <<         [new Account(100),  new Account(10)]
      to <<           [new Account(50),   new Account(90)]
      amount <<       [50,                10]
      fromBalance <<  [50,                0]
      toBalance <<    [100,               100]
 }

Usage

The Spock Arquillian Extension supports both Groovy major versions supported by Spock Framework. In order to select proper versions, you need to put following dependencies into your section:

 <dependency>
     <groupId>org.jboss.arquillian.spock</groupId>
     <!-- replace * with standalone or container, according to your needs -->
     <artifactId>arquillian-spock-*</artifactId>
     <version>${project.version}</version>
     <scope>test</scope>
 </dependency>

 <!-- External Projects -->
 <dependency>
     <groupId>org.spockframework</groupId>
     <artifactId>spock-core</artifactId>
     <version>${version.spock}</version>
     <scope>test</scope>
 </dependency>

 <dependency>
     <groupId>org.codehaus.groovy</groupId>
     <artifactId>groovy-all</artifactId>
     <version>${version.groovy}</version>
     <scope>test</scope>
 </dependency>

For Groovy 2.x, use spock 0.7-groovy-2.0 or later and Groovy 2.1.4 or later

You must annotate the JUnit Runner with the ArquillianSputnik runner.

 @RunWith(ArquillianSputnik.class)

Build

Regular mvn clean install will run tests against Wildfly 8.0.0.Final. Others containers can be used by defining container variable, for example

mvn clean install -Dcontainer="JBoss AS:7.1.1.Final:managed"

This flexibility and is provided by Arquillian Chameleon. For more available containers see default list.

Contents of repository

core/ The Spock Extension itself.

standalone/ Standalone Arquillian test executor.

container/ Container extension which bundles all Spock-related dependencies required while running Spock specifications using Arquillian.

examples/ Sample tests written using Spock BDD framework.

Licensing

This distribution, as a whole, is licensed under the terms of the Apache License, Version 2.0 (see license.txt).

More info

Spock Arquillian

org.jboss.arquillian.spock

An Innovative Testing Platform for the JVM

Versions

Version
1.0.0.Beta3
1.0.0.Beta2
1.0.0.Beta1