Java Reference
In-Depth Information
Running Arquillian tests using Spock
Arquillian is not limited to only JUnit. As we mentioned earlier, there are already contain-
ers, for example, TestNG and Spock; let's focus on the second one.
Spock is a modern testing framework written in Groovy and uses some of the Groovy lan-
guage features to make your tests more readable and easier to write. Spock's primary goal
is to test the Groovy code but it is perfect to write all kinds of tests for the Java code. Spock
introduces a few additional semantics with its Domain Specific Language ( DSL ) in order
to make testing even more easier and developer friendly.
Let's rewrite our previous test example using Spock:
@RunWith(ArquillianSputnik.class)
class TicketServiceTest extends Specification {
@Deployment
def static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class)
.addPackage(SeatType.class.getPackage())
.addPackage(TicketService.class.getPackage())
.addPackage(LoggerProducer.class.getPackage())
.addAsResource('META-INF/persistence.xml')
.addAsWebInfResource(EmptyAsset.INSTANCE,
'beans.xml');
}
@Inject
TicketService ticketService;
def "should create SeatType"() {
given:
def seatType = new SeatType(description: "Balcony",
price: 11, quantity: 6)
when:
ticketService.createSeatType(seatType);
Search WWH ::




Custom Search