17
Testing Java EE Applications using Arquillian Reza Rahman Java EE/GlassFish Evangelist [email protected] @reza_rahman

Testing Java EE Applications Using Arquillian

Embed Size (px)

DESCRIPTION

This session outlines how to effectively test Java EE APIs like JSF, Servlet, CDI, EJB 3, JPA, WebSocket and JAX-RS. Java EE includes a number of new features that enhance testability like generic dependency injection, CDI @Alternative, portable extensions, embedded containers and JSF project stages. Using these features and best of breed tools like JUnit and Arquillian it is possible to perform unit, integration, system and functional testing for Java EE APIs at all layers of the application. In addition to discussing tools and features, the session will also demonstrate testing techniques like designing for testability, mock objects, isolation and test configuration.

Citation preview

Page 1: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public1

Testing Java EE Applicationsusing ArquillianReza RahmanJava EE/GlassFish [email protected]@reza_rahman

Page 2: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public2

Testing, J2EE and Java EE

Testing not addressed well by J2EE Java EE helps enormously by providing a number of enabling features Arquillian takes full advantage of these features Not the only solution, but best-of-breed Developer (unit and integration) testing focus for this talk

– Arquillian can also help with performance, system, etc testing

– Arquillian excels at integration/regression testing

I’ll primarily focus on JUnit, not TestNG– TestNG also supported by Arquillian

Page 3: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public4

Java EE Testing Enablers

Page 4: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5

Testing Servlet

JAX-RS 2 client API comes in very handy! HttpUnit, HtmlUnit good tools as well Traditional problem is bootstrapping containers from tests Simulated Servlet containers like ServletUnit too limited, not the real

runtime environment Mocking Servlet objects with EasyMock or Mockito too much work

Page 5: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public6

Servlet Testing Demo

https://github.com/m-reza-rahman/testing-javaee

Page 6: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public7

Testing JSF 2

JSF 2 project stages invaluable for debugging and testing Warp ideal for complete JSF testing Client and server-side tests Drone/Selenium, Graphene often sufficient

Page 7: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public8

JSF 2 Testing Demo

https://github.com/m-reza-rahman/testing-javaee

Page 8: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public9

Testing CDI/EJB 3

CDI increases Java EE component model level testability by leaps and bounds

Embedded containers, generic dependency injection, @Alternative, portable extensions, XML deployment descriptors, interceptors key enablers

Both mock object based unit testing as well as integration testing is possible

Likely best to stick with integration testing using close to the real runtime environment

Page 9: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public10

Testing JPA

Embedded container, CDI and Arquillian integration works well for JPA Consider using embedded databases like Java DB, Derby, HSQL Defining data sources with the application - @DataSourceDefinition You can use JPA 2.1 data loading, schema generation and DBUnit for

better data consistency Tests can use transactions Take advantage of XML overrides

Page 10: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11

CDI, EJB 3, JPA Testing Demo

https://github.com/m-reza-rahman/testing-javaee

Page 11: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12

Testing JAX-RS, WebSocket (and JAX-WS)

You can use JAX-RS, WebSocket and JAX-WS client APIs with JUnit/Arquillian

For more complex cases consider UI based testing tools (e.g. soapUI for REST and SOAP)

Page 12: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13

JAX-RS, WebSocket Testing Demo

https://github.com/m-reza-rahman/testing-javaee

Page 13: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public14

Arquillian Supported Containers

Container Support

GlassFish Embedded, Managed, Remote

WildFly, JBoss Embedded, Managed, Remote

Weld SE, Weld EE Embedded

TomEE, OpenEJB, OpenWebBeans Embedded, Managed, Remote

WebLogic Managed, Remote

WebSphere, Liberty Managed, Remote

Page 14: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public15

Summary

Robust, end-to-end testing a true reality with modern Java EE EJB 3, JPA 2, CDI, JSF 2, embedded containers, portable extensions,

XML deployment descriptors, client APIs key enablers Range of new and existing tools available to fit your testing

methodology, requirements Arquillian best-of-breed Java EE testing tool Rich set of features, vibrant community Get involved!

Page 15: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16

Learning More

Java EE Tutorials– http://docs.oracle.com/javaee/7/tutorial/doc/home.htm

Arquillian– http://jboss.org/arquillian

The Aquarium– http://blogs.oracle.com/theaquarium

Page 16: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public17

Page 17: Testing Java EE Applications Using Arquillian

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public18

Appreciation Event at Oracle Open World

Join us at the “Thirsty Bear” Join us at the “Thirsty Bear” 661 Howard St 661 Howard St

Sunday, September 28Sunday, September 28

Java EE, GlassFish, WebLogic, Java EE, GlassFish, WebLogic, Coherence developersCoherence developers

Drinks are on us (to a point)Drinks are on us (to a point)

Watch @Reza_Rahman for detailsWatch @Reza_Rahman for details

Annual Java EE appreciation partyAnnual Java EE appreciation party

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |Oracle Confidential – Internal/Restricted/Highly Restricted18