Arquillian Spring Framework Extension 1.0.0.Alpha1 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.Alpha1 release of the Arquillian Spring Framework Extension component!

We’re moving the boundaries of Arquillian into a completely new area by including built-in support for testing applications that use the Spring Framework. This release is the first milestone for this extension. The focus so far has been on providing support for Spring’s core features (e.g., IoC container, data sources, persistence, transactions, javax.inject and EJB integration, etc.).

I’m working on the Spring extension for my Google Summer of Code 2012 project. This post also serves as my first status update. Coding began yesterday, but I’ve already been hard at work ;)

Some of the highlights in this release

Dependency injection

The extension provides three simple ways to enable Spring support in Arquillian test case. In other to create application context from XML simply add to the test @SpringConfiguration with locations of the XML files. Java-based config is supported as well with @SpringAnnotatedConfiguration which can be configured with concrete classes or names of packages to scan. The last possibility, @SpringWebConfiguration that allows to retrieve the application context of the specific DispatcherServlet running in the container, can be used only with web applications.

Custom context classes

There are situations when plain Spring context isn’t enough, so we allowed to register custom context classes that will be instantiated for each test. The context classes could be customized through annotations or through extension settings provided with arquillian.xml. A typical scenario would be for example running the Spring in JBoss AS using Snowdrop custom context classes.

Artifact packaging

The extension, by default, handles packaging of spring-context and spring-web automatically with each test.

Intuitive configuration

The extension can be easily configured through the arquillian.xml. All the settings like e.g. artifacts versions can be overridden here.

arquillian.xml
<extension qualifier="spring">
    <property name="autoPackage">true</property>
    <property name="springVersion">3.0.0.RELEASE</property>
    <property name="cglibVersion">2.2</property>

    <property name="includeSnowdrop">true</property>
    <property name="snowdropVersion">2.0.3.Final</property>

<property name=“customContextClass”>org.jboss.spring.vfs.context.VFSClassPathXmlApplicationContext</property>
</extension>

Here’s an example of a basic Spring test with Arquillian:

DefaultStockRepositoryTestCase.java
@RunWith(Arquillian.class)
@SpringConfiguration("applicationContext.xml")
public class DefaultStockRepositoryTestCase {

    @Deployment
    public static JavaArchive createTestArchive() {
        return ShrinkWrap.create(JavaArchive.class)
                .addClasses(Stock.class, StockRepository.class, StockService.class,
                        DefaultStockRepository.class, DefaultStockService.class)
                .addAsResource("applicationContext.xml");
    }

    @Autowired
    StockRepository stockRepository;

    @Test
    public void testSave() {
        Stock acme = createStock("Acme", "ACM", 123.21D, new Date());
        Stock redhat = createStock("Red Hat", "RHC", 59.61D, new Date());

        stockRepository.save(acme);
        stockRepository.save(redhat);

        assertTrue("The stock id hasn't been assigned.", acme.getId() > 0);
        assertTrue("The stock id hasn't been assigned.", redhat.getId() > 0);
    }
}

For more examples on how to use these extensions and quickly get started with development you can take a look at prepared showcase. Additionally, you can browse the integration tests that are part of project source code.

For help with preparing this release, I’d like to especially thank Dan Allen, Marius Bogoevici and Aslak Knutsen for sharing their knowledge and providing helping hand.

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 Spring Framework Extension
Version 1.0.0.Alpha1 view tag
Release date 2012-05-21
Released by Aslak Knutsen
Compiled against

Published artifacts org.jboss.arquillian.extension

  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-common jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-2.5 jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-2.5-int-tests jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-3 jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-service-deployer-spring-3-int-tests jar javadoc pom

Release notes and resolved issues 2

Support for Spring enrichment in other Containers

Feature Request
  • ARQ-301 - Create a Spring framework integration (for non-standalone containers)

Thanks to the following list of contributors: Jakub Narloch, Aslak Knutsen