Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Arquillian

5,269 views

Published on

Arquillian (http://jboss.org/arquillian) is a test harness that simplifies integration testing using container managed resources.

ShrinkWrap (http://jboss.org/shrinkwrap) is a fluent Java API for dynamically generating deployable archives.

Published in: Technology
  • Be the first to comment

Arquillian

  1. 1. Chris Wash<br />CapTech Ventures<br />FYB Aug 2010<br />
  2. 2. Java EE Development Evolution<br />POJO<br />Model<br />Container <br />Services<br />Ease of<br />Development<br />Ease of<br />Testing<br />Framework<br />Integration<br />Dependency<br />Injection<br />JNDI<br />CMP<br />EJB2.x<br />Struts<br />Hibernate<br />EJB3<br />JPA<br />JSF<br />CDI<br />Weld<br />Spring<br />Arquillian<br />Seam<br />“Lightweight” movement<br />Grails<br />
  3. 3. Shift Focus to Testing in EE<br />Lots of developers abandoned EE in search of greener “testing” pastures.<br />Testing has not been the focus for most of the platform’s history.<br />Ride the wave… encourage support and adoption<br />Dev-friendly container-based component models cry out for ease of testability!<br />
  4. 4. Real EE Testing<br />What does “real” mean?<br />Unit testing using doubles can only get us so far when working with container managed resources.<br />Want to be confident we get the interactions correct between container managed resources<br />Short feedback cycle when making a change<br />
  5. 5. Integration Testing<br />
  6. 6. Rolling Your Own<br />How do I get unit test class into the container?<br />Remote deployment (using hook into server)<br />Bootstrap container inside test<br />How do I exercise the code under test?<br />How do I see the results of the test?<br />How does test isolation work?<br />Test classpath-hell<br />Can I call it from IDE and get results?<br />
  7. 7. Challenges to testing in container<br />High barrier to entry<br />Substantial code, configuration and infrastructure<br />Most don’t run from IDE - where’s the feedback?<br />Most aren’t reusable – tied to 1 project’s build<br />Often slow (think “mvn package”)<br />Can’t interact with containers from test (all black-box testing)<br />Enough ROI to justify work/maintenance?<br />
  8. 8. CDI (JSR-299) TCK + ALR EJB3 book examples<br />Used by Weld<br />Plan to be used by JBossAS<br />“Ike” - controls everything in his little world<br />Good way to learn CDI, EJB, JPA, etc.<br />
  9. 9. Arquillian Features<br />JUnit or TestNG compatible<br />Abstracts out server lifecycle and deployment<br />Injects container managed resources into test<br />Zero reliance on build – run straight from IDE<br />Two container modes – remote/embedded<br />Pass-by-reference between test and server<br />Even across JVMs<br />Extensible SPI to plug any container in<br />Single test executed against all containers<br />
  10. 10. Arquillian Architecture<br />
  11. 11. Arquillian: Flexibility<br />Out of the box, supports multiple:<br />Test frameworks (JUnit, TestNG)<br />Containers<br />Enrichers<br />Run Modes<br />Most things are pluggable<br />API/SPI<br />Modular design<br />
  12. 12. ShrinkWrap<br />“Skip the Build!”<br />Fluent API for describing deployable archives<br />Apache-licensed<br />Zero transitive-dependency promise<br />Solves test-classpath madness<br />Removes dependency of integration tests on packaging<br />Creates fine grained archives<br />Contains only what you need<br />
  13. 13. ShrinkWrap<br />
  14. 14. ShrinkWrap<br />IDE can perform incremental compilation<br />Change a class that is ShrinkWrap’d, only that class needs to be recompiled (no repackaging)<br />Poor man’s “hot swap”?<br />Future support tooling views in IDEs<br />See what your archive would look like when SW is executed<br />
  15. 15. ShrinkWrap – Arquillian Integration<br />Simple – method annotated @Deployable within your test class<br />Gets called by ShrinkWrap when deploying your archive, “bundles it” on the fly<br />
  16. 16. Containers<br />Loosely defined, anything that accepts an archive deployment and provides services<br />Arquillian finds specified DeployableContainer SPI on classpath<br />Multiple containers already supported, fairly easy to add support for a container<br />Configured by using Maven profiles, e.g.<br />mvn test –Pjbossas-remote-6<br />
  17. 17. Container Modes<br />Describes how the test archive should be deployed<br />Embedded<br />Same JVM<br />Bootstraps container, often “standalone” environment<br />Managed<br />Different JVM, same machine<br />Server will be started/stopped as part of the test run<br />Remote<br />Different JVM, different machine<br />Server startup/shutdown not controlled by ARQ<br />Arquillian controls binding/unbinding to server<br />
  18. 18.
  19. 19. Container Support<br />Notably, no Weblogic and no WebSphere yet<br />Looking for community contribution<br />No Spring or Hibernate yet, but they’re planned.<br />
  20. 20. Enrichers<br />Allow for injections into your test from within a container<br />Out of the box, supports:<br />@Resource (ghetto!)<br />@EJB (a few caveats)<br />@Inject (CDI)<br />Transparent to user – internal lifecycle step before executing test methods<br />
  21. 21. Run Modes<br />IN_CONTAINER<br />AS_CLIENT<br />Arquillian uses this when running your test (after enrichment)<br />Determines which side of the client/server divide the test method should be executed on<br />See LocalRunServletTestCase<br />
  22. 22. Embedded Lifecycle<br />Bundle test archive*<br />Use ShrinkWrap’d archive<br />Bootstrap container<br />Deploy archive to container<br />Enrich test class<br />Execute tests<br />After execution, undeploy archive<br />Stop container<br />Display captured test results<br />
  23. 23. Managed Lifecycle<br />Bundle test archive*<br />Use ShrinkWrap’d archive<br />Add test class and invoker<br />Bootstrap server<br />Deploy archive to container<br />Enrich test class<br />Negotiate test method execution (based on Run Mode)<br />Collect test results, return back thru Arquillian<br />After execution, undeploy archive<br />Stop server<br />Display test results returned from server<br />
  24. 24. Remote Lifecycle<br />Bundle test archive*<br />Use ShrinkWrap’d archive<br />Add test class and invoker<br />Bind to container<br />Deploy archive to container<br />Inside container, enrich test class<br />Negotiate test method execution (based on Run Mode)<br />Collect test results, return back thru Arquillian<br />After execution, undeploy archive<br />Unbind from container<br />Display test results returned from server<br />
  25. 25. Test Execution/SPI Overview<br />
  26. 26. Demo<br />
  27. 27. The Cons<br />Lack of true test isolation<br />Implementing feature to deal with isolation<br />If using an Embedded container you’re in a “Simulated” environment<br />Easy to turn an embedded test into a remote test<br />
  28. 28. The Pros<br /> Scale up to the level of integration you need by growing your test archive<br />Rely on shared memory<br />Don’t have to return/serialize a lot of state just to do asserts on<br />Pass-by-reference works<br />Don’t need remote views exposed just to test<br />Managed concurrency<br />Multiple containers for free<br />
  29. 29. Future<br />*Bundling – read Maven pom.xml and run through dependency resolution algorithm to include required dependencies<br />Support for more Containers<br />Performance monitoring<br />Archive “bundle-time” class manipulation<br />Exception, Callback, Assertion injection<br />Component coverage recording<br />Tooling support<br />Framework integration<br />Selenium, HTTPUnit, DBUnit, easyB<br />
  30. 30. #jbosstesting initiatives<br />Establish testing culture in Java EE!<br />Other frameworks<br />Placeebo – Mock Java EE API implementations (Fakes)<br />JSFUnit – Gray-box JSF testing (Pretty cool, if you’ve seen SeamTest in action)<br />
  31. 31. Further Info<br />Chris Wash, @cwash (Twitter, Yammer)<br />Use #testrevolutionhashtag<br />Material jacked from the following sites:<br />http://github.com/arquillian/arquillian-showcase<br />http://www.slideshare.net/mojavelinux/real-javaeetestingwithanswers<br />http://docs.jboss.org/arquillian/reference/latest/en-US/html_single<br />IRC #jbosstestingirc.freenode.net<br />Sites<br />http://jboss.org/arquillian<br />http://jboss.org/shrinkwrap<br />Source<br />http://github.com/arquillian<br />

×