Arquillian gets Spring in step

Arquillian enters new territory with Spring Framework Extension

The Arquillian team don't appear to be letting up since last month's 1.0 release, adding in a raft of new extensions for the JVM testing platform over the past few weeks. We've seen an Arquillian Portal Extension and a Jacoco one too, now the big hitter comes onboard with 1.0.0.Alpha1 release of the Arquillian Spring Framework Extension component.

Built-in support for Spring applications testing is completely new territory for Arquillian but a shrewd decision to welcome those developers into the fold. Jakub Narloch revealed on the Arquillian blog that the Spring Framework Extension would be his Google Summer of Code 2012 project - an initiative that the Arquillian have more than warmed to, with two slots alloted to them in JBoss's 8.

This first milestone indicates that the rock solid foundations for the Spring Framework have been put in place. Dependency injection, custom context classes, artifact packaging and intuitive configuration have all been touted in the highlight reel and from the looks of things, it's an exceptionally strong first effort.

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

 

@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);
    }
}

 

Not bad eh? Head over to GitHub for more examples of this nature. We're eager to see the next alpha release for this and it becoming an Arquillian stalwart component in the longrun.

Arquillian is named after a small alien in Men In Black, and you'd expect both to be summer blockbusters. Yet again, Arquillian has simplified Java middleware testing.

Chris Mayer

What do you think?

JAX Magazine - 2014 - 06 Exclucively for iPad users JAX Magazine on Android

Comments

Latest opinions