The Danger of Embedded Containers

In the Arquillian project, we’re all about real tests. There’s a good reason for this philosophy. If you use mocks or a substitute container when testing code that uses a programming model (i.e., CDI), all you can be sure of is that you’ve faked out enough functionality to get the test to work. You can’t be certain that your code works—really, truly works.

Obviously, we provide adapters for embedded containers (i.e., substitute containers). The reason is, they often do a decent enough job of simultating the real environment that we are willing to make the trade-off for its variations when we are working in development. I would expect, though, that you are also running the same tests in CI using a real container…just to get that peace of mind.

How do you know when not to use an embedded container?

If you write a test that you are positive should work, but instead throws some wacky exception, immediately stop and try the same test in a real container. For example, if you are using Embedded GlassFish, I would advise running the test in managed or remote GlassFish. The latter two adapters both use an authentic GlassFish instance. If the test passes, then you have answered the question of this section.

When the embedded container begins to act inconsistently, drop it.

As with all things, there are exceptions to the rule. If the code really should work on the embedded container, then it may be worth exploring why it isn’t. That may lead you to the discovery of a bug in the library you’re using. If debugging the library is your main concern, chase it down. If you are just trying to get a test written for your application, stop using the embedded container (or save debugging it for a rainy day).

Examples

See this thread in the Seam 3 forums for an example where the Embedded GlassFish container was acting more of a hindrence than a help. The thread includes the steps I took to get a green bar using a different GlassFish container adapter.

Markus Eisele identifies another hazard. He points out in a recent blog post that testing JPA using Embedded GlassFish is problematic because JPA weaving (in EclipseLink) does not occur:

[Weaving] only works when the entity classes to be weaved only exist in the application classloader. The combination of Embedded GlassFish, Arquillian and the Maven Surefire Plugin mix this up a bit and the end of the story is, that exactly none of your entities are enhanced at all.

Again, testing on Embedded GlassFish is not serving us well in this scenario. Graduate.

Closing thoughts

Code that uses Solder works fine on GlassFish 3.1.2, but it does not play very nicely with Embedded GlassFish—it’s just a hostile environment for CDI because of the visibility issues that come with starting an embedded container inside an existing Java process. The same goes for JPA. You end up in a minefield of class visibility and access problems, and far from making any progress writing tests (your ultimate goal).

If you want the container to start automatically like with embedded, then switch to a managed container. It works almost exactly the same as the remote container, except that Arquillian will start the standalone process at the beginning of the test execution and stop it at the end. In other words:

managed >>>> embedded

It’s clean. It’s true.

For speed of development:

remote > managed

With remote, you don’t have to wait for the container to start…and you can start it in debug mode very easily and keep it there. That’s why I say that the best container adapters for development are the remote adapters and the best adapters for CI are the managed adapters. I personally don’t like the embedded container adapters much (with the exception of embedded CDI since that’s mostly a pure standalone CDI environment).

Keep that advice in mind.

Arquillian Persistence Extension 1.0.0.Alpha4 Released

Since we wrote this post we didn't laze around. Check our latest announcement.

The Arquillian team is proud to announce the 1.0.0.Alpha4 release of the Arquillian Persistence Extension component!

It’s been a while since the Alpha3 release. After three long months, we’re excited to announce Alpha 4 with a lot of improvements and enhancements suggested by our great community. Best of all, we finally have complete documentation in the reference guide!

I would especially like to thank Michael Brill for nailing down DBUnit clean up strategies, Pål Oliver Kristiansen and Jarek Gilewski for suggesting customization of DBUnit behaviour and Juergen Zimmermann for spotting a bug with transactional support. Last, but not least, many thanks to all who actively discussed the roadmap for next releases. There is plenty of great stuff on the way! Thank you very much for your feedback!

Some of the highlights in this release

Custom SQL scripts for cleanup
You can now use custom SQL scripts to clean your database before or after the test. For this purpose use the @CleanupUsingScript annotation and specify SQL files which have to be executed.
More flexible custom SQL scripts execution
We’ve removed the @UsingScript annotation and replaced it with the @ApplyScriptBefore and @ApplyScriptAfter annotations.
DBUnit insert strategies

You can tell DBUnit how it should insert your data. The following strategies are available:

  • INSERT – Performs insert of the data defined in provided data sets. This is the default strategy.
  • CLEAN_INSERT – Performs insert of the data defined in provided data sets, after removal of all data present in the tables referred in provided files.
  • REFRESH – During this operation, existing rows are updated and new ones are inserted. Entries already existing in the database which are not defined in the provided data set are not affected.
  • UPDATE – This strategy updates existing rows using data provided in the datasets. If the dataset contains a row which is not present in the database (identified by its primary key) then an exception is thrown.
DBUnit cleanup modes

You can specify when and how you would like your database to be cleaned. By default, your database is erased entirely before each test. If you want to control this behavior, use the @Cleanup annotation for this purpose. The following modes are currently supported:

  • STRICT – Cleans the entire database. This strategy might require turning off database constraints (e.g. referential integrity).
  • USED_ROWS_ONLY – Deletes only those entries that are defined in the datasets used for seeding.
  • USED_TABLES_ONLY – Deletes only those tables that are referenced in datasets.

You can also specify when you would like to invoke the cleanup procedure. For instance:

@Cleanup(phase = TestExecutionPhase.AFTER, strategy = CleanupStrategy.USED_ROWS_ONLY)

You can invoke cleanup BEFORE or AFTER the test. You can also disable cleanup by using TestExecutionPhase.NONE.

Column filtering for data set matching
@ShouldMatchDatSet has been enhanced with columnsToExclude list, where you can specify which columns shouldn’t be used for database content verification.
Nullable columns
For XML, JSON and YAML you can now set arbitary columns to null using [null] placeholder.
Separated configuration for core and (enhanced) DBUnit specific features

We provide configuration for all DBUnit properties and features as of Alpha 4! Moreover there is a split for core properties (such as default data source or JNDI of UserTransaction) and DBUnit related settings, as the example below illustrates:

arquillian.xml
<extension qualifier="persistence">
    <property name="defaultDataSource">java:app/datasources/mssql_ds</property>
    <property name="userTransactionJndi">java:jboss/UserTransaction</property>
    <property name="initStatement">scripts/mssql-identity-insert-on.sql</property>
    <property name="cleanupStatement">scripts/mssql-identity-insert-off.sql</property>
</extension>
          
          <extension qualifier=“persistence-dbunit”>
<property name=“datatypeFactory”>org.dbunit.ext.mssql.MsSqlDataTypeFactory</property>
<property name=“useIdentityInsert”>true</property>
</extension>

For complete list, please refer to the reference guide.

We look forward to hearing your feedback about this release in the community forums!

What is Arquillian?

Arquillian is open source software that empowers you to test JVM-based applications more effectively. Created to defend the software galaxy from bugs, Arquillian brings your test to the runtime so you can focus on testing your application's behavior rather than managing the runtime. Using Arquillian, you can develop a comprehensive suite of tests from the convenience of your IDE and run them in any IDE, build tool or continuous integration environment.

Release details

Component Arquillian Persistence Extension
Version 1.0.0.Alpha4 view tag
Release date 2012-04-12
Released by Aslak Knutsen
Compiled against

Published artifacts org.jboss.arquillian.extension

  • org.jboss.arquillian.extension » arquillian-persistence-api jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-persistence-impl jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-persistence-integration-tests jar javadoc pom

Release notes and resolved issues 21

Enhancement
  • ARQ-755 - Introduce annotation based db cleanup configuration
  • ARQ-756 - Improve error messages
  • ARQ-805 - Convert test method names from camel to underscore
  • ARQ-859 - Cleanup configuration - move dbunit related settings to its own configuration.
Feature Request
  • ARQ-718 - Customization for DBUnit
  • ARQ-719 - Enable column sensing for FlatXmlDataSet
  • ARQ-720 - Enable nulls for FlatXmlDataSet
  • ARQ-764 - Using DBUnit with IDENTITY or auto-increment columns
  • ARQ-777 - Should be possible to run custom scripts before and after test
  • ARQ-804 - Should be able to clean database using custom SQL script
  • ARQ-869 - Move JavaDoc from Field level to Method level for Configuration objects
Bug
  • ARQ-721 - Compilation error in older version of JDK 6
  • ARQ-723 - TransactionalWrapper.afterTest() ignores SessionContext.setRollbackOnly()
  • ARQ-751 - Empty YML file is causing error whereas it should be simply skipped
  • ARQ-752 - Persistence extension is failing to enrich archive when there is no dataset defined
  • ARQ-765 - Update ShrinkWrap Descriptors dependency
Task
  • ARQ-757 - Document extension in confluence.
Sub-task
  • ARQ-771 - Global DBUnit configuration should be exposed in arquillian.xml
  • ARQ-772 - Introduce column filtering for data set matching
  • ARQ-806 - Should provide cleanup strategies to control what needs to be removed for the given test

Thanks to the following list of contributors: Bartosz Majsak, Aslak Knutsen

Graphene 1.0.0.Final Released

Since we wrote this post we didn't laze around. Check our latest announcement.

The Arquillian team is proud to announce the 1.0.0.Final release of the Graphene component!

Graphene is joining rest of the Arquillian party, building on top of Arquillian testing platform Drone extension, both which reached their first stable version yesterday.

The Mission

Arquillian Graphene focuses on making real-browser automation a breeze.

The project was started to address simplification of covering AJAX-enabled applications with browser automation tests.

While Selenium project is focusing on unified API, integration with variety of browsers, Graphene project is addressing the real-world testing challenges:

  • rapid development
    • straight-forward
    • readable API
    • fast turnaround
  • object-oriented
    • type-safe API
    • dependency injection of thread-local context
  • instabilities and speed of execution in continuous integration
    • jQuery selectors
    • request guards

Availability

The Graphene bits are available in JBoss Community artifact repository, dual-licensed under LGPL v2.1 (backward-compatibility) and ASL v2.0 (which uses rest of the Arquillian sub-projects).

For those who are already using Graphene in a Maven project, you can simply update the version to 1.0.0.Final.

You can start with the tests using our Getting Started with the JBoss Maven repository guide.

The Future

Right now we are heavily working on making the new version of Graphene 2 on the road.

Selenium 2 with its WebDriver API made huge progress with API accessibility and readability. It’s already pleasure to work with this API in Java world.

However still there are many shortcomings we are going to address with Graphene 2, building on top of concepts brought in Graphene 1 and adding new features, which opens world of new possibilities:

  • dependency injection of thread-local context
  • fast development turnaround
  • cross-cutting concerns (command interception)
  • request guards
  • page extensions
  • component objects
    • extension of page objects concept
  • JavaScript test execution from within Selenium test

If you enjoy testing and you are unsatisfied with the current browser automation tooling, it’s perfect time to step in and help us to bring the future!

Project Links

What is Arquillian?

Arquillian is open source software that empowers you to test JVM-based applications more effectively. Created to defend the software galaxy from bugs, Arquillian brings your test to the runtime so you can focus on testing your application's behavior rather than managing the runtime. Using Arquillian, you can develop a comprehensive suite of tests from the convenience of your IDE and run them in any IDE, build tool or continuous integration environment.

Release details

Component Graphene
Version 1.0.0.Final view tag
Release date 2012-04-11
Released by Lukas Fryc
Compiled against

Published artifacts org.jboss.arquillian.graphene

  • org.jboss.arquillian.graphene » graphene-parent pom
  • org.jboss.arquillian.graphene » graphene-selenium-parent pom
  • org.jboss.arquillian.graphene » graphene-selenium-api jar javadoc pom
  • org.jboss.arquillian.graphene » graphene-selenium-impl jar javadoc pom
  • org.jboss.arquillian.graphene » graphene-selenium-drone jar javadoc pom
  • org.jboss.arquillian.graphene » graphene-selenium pom
  • org.jboss.arquillian.graphene » arquillian-graphene pom

Release notes and resolved issues 8

Component Upgrade
  • ARQGRA-140 - Upgrade to Arquillian Core/Drone 1.0.0.Final
Feature Request
  • ARQGRA-142 - Refactor Graphene 1 to allow addition of Graphene 2 bits
  • ARQGRA-143 - Add license file to the project
  • ARQGRA-144 - Add section about Drone/Graphene usage in Getting Started guide
Bug
Task
  • ARQGRA-93 - Add README to the GitHub repository
  • ARQGRA-139 - Blog about releasing Graphene 1 Final
  • ARQGRA-145 - Update dependency versions in docs

Thanks to the following list of contributors: Lukas Fryc

Death to all bugs! Arquillian testing platform reaches first stable release

Red Hat, Inc. and the JBoss Community today announced the 1.0.0.Final release of Arquillian, its award-winning testing platform built to run on the Java Virtual Machine (JVM). Arquillian substantially reduces the effort required to write and execute Java middleware integration and functional tests. It even enables test engineers to address scenarios previously considered untestable or too expensive to test.

The Arquillian project is led by Aslak Knutsen and has received contributions from over 100 contributors and community members (between Arquillian and ShrinkWrap combined). At the JavaOne 2011 conference, Arquillian received the Duke’s Choice Award for innovation in integration testing.

The 1.0.0.Final release of Arquillian Drone, a key add-on to the platform, is included in this release. Final versions of select container adapters will be released later in the week. ShrinkWrap, a central component of Arquillian, announced its 1.0.0.Final release last week.

Mission and History

Arquillian adheres to three core principles:

  • Tests should be portable to any supported container
  • Tests should be executable from the IDE to eliminate the need for an explicit build step and to simplify debugging
  • The platform should unify the Java testing ecosystem by extending or integrating with existing test frameworks

By focusing on these principles, Arquillian makes integration and functional tests as simple to write and execute as unit tests.

Arquillian originated from the test harness developed for the CDI 1.0 (JSR-299) specification in 2009. It spun off as an independent project and has evolved into an extensible testing platform. Coming full circle, the test suite in CDI 1.1 (JSR-346), the next iteration of the CDI specification, has migrated to Arquillian. Other specifications are expected to follow. Arquillian is also used by numerous open source projects, including Hibernate, JBoss AS 7, Drools, RHQ, JClouds and Apache DeltaSpike.

Functionality

Arquillian brings test execution to the target runtime, alleviating the burden on the developer of managing the runtime from within the test or project build. To invert this control, Arquillian wraps a lifecycle around test execution that does the following:

  • Manages the lifecycle of one or more containers
  • Bundles the test case, dependent classes and resources as ShrinkWrap archives
  • Deploys the archives to the containers
  • Enriches the test case with dependency injection and other declarative services
  • Executes the tests inside (or against) the containers
  • Returns the results to the test runner for reporting

Arquillian runs with Java 1.5 and above, integrates seamlessly with familiar testing frameworks such as JUnit and TestNG and allows tests to be launched using existing IDE, Ant and Maven test plugins.

Loving quotes about Arquillian

…using Arquillian, we were able to cut the setup needed to run a plugin in-container by 90% and we were able to introduce a number of convenience annotations from which you can get a variety of data injected into your tests.”

— Lukáš Krejčí, RHQ core developer

Arquillian is a really great integration testing tool full of potential. It’s just great that the JBoss guys are aiming to provide support for almost all widely used application servers and web containers. If you are writing an application for the Java EE 6 stack, not using Arquillian is a serious mistake!”

— Bartosz Majsak, Cambridge Technology Partners

[Arquillian] reminds me of the old Cactus project back in the day, but done much, much better.”

— Laird Nelson

Newest features

Arquillian can manage more than a dozen container vendors, including JBoss AS, GlassFish and Tomcat, and supports running tests in cloud services. The container support allows developers to target a variety of technology platforms, including Java EE 5 and 6, Servlet environments, OSGi, Embedded EJB and standalone CDI.

Additional new features include:

  • Orchestration of multiple deployments across multiple containers in a single test
  • Support for multiple protocol contexts within a single deployment
  • Descriptor deployment
  • Assertions for deployment exceptions
  • A new configuration schema that supports multiple configurations per container
  • EL-like evaluation in properties and configuration overrides via Java properties
  • Explicit ordering of test methods
  • Control over when the container is started and stopped

Arquillian’s extensibility is reflected in its growing ecosystem of extensions. The most mature extension, Arquillian Drone, is included in today’s release. Drone is an abstraction over browser controllers such as Selenium and WebDriver that enables the developer to write browser-based tests without having to fuss with the typical setup and plumbing. Other extensions under active development include an Android test controller, DBUnit integration, a SeamTest replacement for testing Seam 2, BDD runners (Spock and JBehave), performance metrics, code coverage (Jacoco) and Arquillian Graphene (a type-safe Selenium API). Expect more extensions to emerge now that the platform has reached a stable release.

Availability

The Arquillian platform and extensions are available in the Maven Central and JBoss Community artifact repositories. The Arquillian libraries are typically added to the test suite of a project using a dependency management tool such as Apache Maven or Apache Ivy. Instructions for setting up Arquillian in your project and writing Arquillian tests are covered in the newly-minted Arquillian Guides.

Arquillian is released under the Apache License, v2.0, an OSI-approved open source software license.

For more information and updates about the Arquilian project, follow the Arquillian project blog and circle the Arquillian project on Google+.

Arquillian Drone Extension 1.0.0.Final Released

Since we wrote this post we didn't laze around. Check our latest announcement.

The Arquillian team is proud to announce the 1.0.0.Final release of the Arquillian Drone Extension component!

What is Arquillian?

Arquillian is open source software that empowers you to test JVM-based applications more effectively. Created to defend the software galaxy from bugs, Arquillian brings your test to the runtime so you can focus on testing your application's behavior rather than managing the runtime. Using Arquillian, you can develop a comprehensive suite of tests from the convenience of your IDE and run them in any IDE, build tool or continuous integration environment.

Release details

Component Arquillian Drone Extension
Version 1.0.0.Final view tag
Release date 2012-04-10
Released by Aslak Knutsen
Compiled against

Published artifacts org.jboss.arquillian.extension

  • org.jboss.arquillian.extension » arquillian-drone-bom pom
  • org.jboss.arquillian.extension » arquillian-drone-selenium-depchain pom
  • org.jboss.arquillian.extension » arquillian-drone-webdriver-depchain pom
  • org.jboss.arquillian.extension » arquillian-drone-api jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-drone-spi jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-drone-configuration jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-drone-impl jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-drone-selenium-server jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-drone-selenium jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-drone-webdriver jar javadoc pom

Release notes and resolved issues 3

Extension Drone - Final

Enhancement
  • ARQ-551 - Update Arquillian Drone docs
Task
  • ARQ-843 - Remove parent artifact from Arquillian-Drone-BOM

Thanks to the following list of contributors: Karel Piwko, Aslak Knutsen