Testing Java EE Applications Using Arquillian

23,065 views

Published on

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.

Published in: Technology
0 Comments
19 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
23,065
On SlideShare
0
From Embeds
0
Number of Embeds
14,920
Actions
Shares
0
Downloads
168
Comments
0
Likes
19
Embeds 0
No embeds

No notes for slide

Testing Java EE Applications Using Arquillian

  1. 1. Others Talk, We Listen. Testing Java EE Applications using Arquillian Reza Rahman Senior Architect rrahman@captechconsulting.com @reza_rahman
  2. 2. CapTech Full-service US national IT consulting firm that focuses on client best interests, trust, servant leadership, culture, professionalism and technical excellence. #28 in Vault's Consulting Top 50 #3 Best Consulting Internship #9 Best Overall Internship #1 in Meeting Client’s Needs #7 Best Firm to Work For #1 in Career Development Ranked for the 7th Consecutive Year Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  3. 3. Testing, J2EE and Java EE • Testing not addressed well by J2EE • This has changed enormously with Java EE and Arquillian • Java EE provides 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 Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  4. 4. Testing Servlet • Traditional problem is bootstrapping containers from tests • Arquillian helps by coordinating container life-cycle • Tests close to production environments • Also helps isolate tests • JAX-RS 2 client API comes in very handy • Java SE 9 may have a better HTTP client API • HtmlUnit, HttpUnit non-standard alternatives Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  5. 5. Servlet Testing Demo https://github.com/m-reza-rahman/testing-javaee Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  6. 6. Testing JSF • Same general concept as Servlet testing • Warp ideal for complete JSF testing • Client and server-side tests from Arquillian • Drone/Selenium, Graphene often sufficient • Just the client side Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  7. 7. JSF Testing Demo https://github.com/m-reza-rahman/testing-javaee Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  8. 8. Testing CDI/EJB 3 • EJB 3 significantly more testable as it is merely POJOs • CDI increases Java EE component model level testability by leaps and bounds • Embedded containers, generic POJO dependency injection, @Alternative, XML deployment descriptors, interceptors major enablers • Arquillian test enrichment through injection, scoping • Both mock object based unit testing as well as integration testing is possible • Likely sufficient to stick with integration testing using close to real runtime environments Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  9. 9. Testing JPA • CDI, EJB 3 and Arquillian works towards JPA testing • Just testing JPA code is possible too but likely unnecessary • JPA 2.1 data loading, schema generation • Defining data sources within the application • persistence.xml, orm.xml XML overrides • Embedded databases like Java DB, Derby, HSQL • DBUnit integration for better data consistency • Tests can use transactions in Arquillian Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  10. 10. CDI, EJB 3, JPA Testing Demo https://github.com/m-reza-rahman/testing-javaee Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  11. 11. Testing JAX-RS, WebSocket (and JAX-WS) • Same general concept as Servlet testing • You can use JAX-RS, WebSocket and JAX-WS client APIs with Arquillian • For more complex cases consider UI based testing tools (e.g. soapUI for REST and SOAP) • JUnit integration possible Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  12. 12. JAX-RS Testing Demo https://github.com/m-reza-rahman/testing-javaee Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  13. 13. WebSocket Testing Demo https://github.com/m-reza-rahman/testing-javaee Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  14. 14. Arquillian Supported Containers Copyright © 2015 CapTech Ventures, Inc. All rights reserved. Container Support GlassFish Embedded, Managed, Remote WildFly, JBoss Embedded, Managed, Remote Weld SE, Weld EE Embedded TomEE, OpenEJB, OpenWebBeans Embedded, Managed, Remote WebSphere, Liberty Embedded, Managed, Remote WebLogic Managed, Remote
  15. 15. Summary • Robust, end-to-end testing a true reality with modern Java EE • A number of key enablers in Java EE • Arquillian best-of-breed Java EE testing tool • Rich set of features, vibrant community Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  16. 16. Resources • Java EE Tutorials • http://docs.oracle.com/javaee/7/tutorial/doc/home.htm • Arquillian • http://jboss.org/arquillian Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  17. 17. Copyright © 2015 CapTech Ventures, Inc. All rights reserved.

×