Book Image

Arquillian Testing Guide

By : John D. Ament
Book Image

Arquillian Testing Guide

By: John D. Ament

Overview of this book

<p>Integration testing sometimes involves writing complex codes. This book introduces you to the capabilities of Arquillian to enable you to write simple code with a broad range of integration tests for java applications. <br /><br />Arquillian Testing Guide serves as an introductory book to writing simple codes for testing java applications. This book will help you to develop richer test cases which can be run automatically while performing rigorous testing of the software. <br /><br />Arquillian Testing Guide introduces you to Arquillians features and capabilities. This book will help you understand the mechanism of creating deployments and test against those deployments. The book begins with basic JUnit test cases beginning with an enterprise test case, which then go on to discuss remote testing. During the course of the book, you will also learn how to mix container and non-container tests into a single test case. By the end of the book, you will have learned how to extend JUnit tests to work with Arquillian and deploy them to a container automatically.</p>
Table of Contents (17 chapters)

Preface

Automated testing has existed in some form for quite some time. Arquillian is a fairly new framework that has its roots around test-driven development and TCK validation for Java EE applications. Its use has grown into full-on application testing, supporting capabilities such as automatically seeding data to deploying to a large cluster of application servers.

Arquillian is a growing framework for automated testing of Java EE applications. Arquillian Testing Guide is meant to focus on how to use Arquillian to build automated test cases for your Java applications. We step through a large suite of the extensions available on top of Arquillian that you can add to your Maven-based projects to extend your testing capabilities.

This book starts with a quick drop into using Arquillian, and then navigates a little bit of testing history. We move on to Arquillian's container support and troubleshooting needs. We talk a lot about test enrichment strategies and capabilities that Arquillian adds to your test setup.

What this book covers

Chapter 1, The Aliens Have Landed!, helps us dive head first into Arquillian with some easy to read CDI examples. We go through the structure of an Arquillian enriched test case to understand what you'll see and where.

Chapter 2, The Evolution of Testing, shows that Arquillian has very deep roots in older test strategies and frameworks. We talk about some of these, how Arquillian grew from them, and how Arquillian can extend them.

Chapter 3, Container Testing, covers one of the key differences with Arquillian, its use of container deployments to execute tests. We go through the suite of these containers and how you may want to use them in your tests.

Chapter 4, Why Did the Test Fail?, explains how sometimes trying to figure out why something isn't passing can be difficult, even more when we have a full application server to deploy. This chapter will help you debug those tests.

Chapter 5, Enriching the Enterprise Test Case, goes through the built-in capabilities and when you can or cannot inject, as enrichment is how Arquillian provides injection support to your test case.

Chapter 6, Arquillian Extensions, builds upon the enrichment process; we look at some important extensions to Arquillian and alternative test runners.

Chapter 7, Functional Application Testing, focuses on the functional testing capabilities of Arquillian. We review Drone, Warp, and Graphene to show how to build out functional tests.

Chapter 8, Service Testing, focuses on service testing, such as EJBs, Soap Web Services, or REST APIs will be covered here.

Chapter 9, Arquillian and OSGi, focuses on how to use JBoss OSGi as your container runtime with Arquillian-based tests.

Chapter 10, ShrinkWrap in Action, illustrates how using Java code to create Java archives has never been as easy as when ShrinkWrap came to town.

What you need for this book

To run the examples in the book, the following software will be required:

  • Maven:

    • Maven 3.0.3 or newer

  • IDE: (pick one)

    • Eclipse with m2eclipse plugin

    • Netbeans

    • IntelliJIDEA

  • Application servers:

    • Apache TomEE 1.5 or higher (preferably TomEE+)

    • JBoss AS 7.1.1 or higher

Who this book is for

This book is focused on developers and testers alike. Developers will find this book useful if they have previously worked with JUnit, are familiar with Java EE application development, and are interested in learning more about building more in-depth test cases.

Testers will find this book useful if they have used tools such as Selenium or soapUI to test their applications in an automated fashion and want to try a new tool. You'll learn some more about how to automatically deploy the applications that you test and use some additional tools to test more robustly.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The @RunWith annotation tells JUnit to use the Arquillian runner for running this class."

A block of code is set as follows:

  @Test
  public void testCalculationOfBusinessData() {
    CalculatorData cd = new CalculatorData(1, 3, 5);
    CalculatorService ms = new CalculatorServiceImpl();
    ms.calculateSum(cd);
    assertEquals(1 + 3 + 5, cd.getResult());
  }  

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public class TestUtils {
  public static JavaArchive createBasicJar() {
    return ShrinkWrap.create(JavaArchive.class,"test.jar")
        .addAsManifestResource(EmptyAsset.INSTANCE,"beans.xml")
        .addPackages(false,getCorePackages());
  }

Any command-line input or output is written as follows:

mvn clean install –Popenwebbeans-embedded-1

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: " If you click on Edit, the selected row will be shown".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.