Help

I'm happy to announce the first alpha release of Arquillian, an open source (ASL v2) framework for running tests in the container. If you want to read more about Arquillian's mission, and how it fits into our vision for testing at JBoss, read Pete's blog.

It's one thing to unit test your code outside of the container, but what happens when you run it inside? Does it still behave the same? How about testing against container managed resources? This is where Arquillian comes into its own.

With Arquillian it's just as easy to write integration tests as unit tests. In fact, to minimize the burden on you, Arquillian integrates with familiar testing frameworks, allowing reuse of tools such as the JUnit/TestNG support in your favorite IDE, Maven Surefire, Ant - in fact any tool which supports TestNG or JUnit!

To show you just how simple this is, here's an example test case setup using JUnit: (we'll get to the actual test next)

@RunWith(org.jboss.arquillian.junit.Arquillian.class)
public class TemperatureConverterTestCase {

   @Deployment
   public static JavaArchive createTestArchive() {
      return Archives.create("test.jar", JavaArchive.class)
         .addClasses(TemperatureConverter.class, TemperatureConverterBean.class);
   }

}

By using JUnit's @RunWith annotation, you tell JUnit to use Arquillian as the test controller. Arquillian will then look for a static method marked with the @Deployment annotation, which creates your micro deployment. In the example above we simply deploy a session bean interface and implementation.

Arquillian hooks into your testing frameworks lifecycle and reacts to events. On the before suite and after suite events the container is started/stopped, while on the before class and after class events your micro deployment is deployed to/undeployed from the container.

The test case is started in the local JVM, and then Arquillian overrides the normal test execution and migrates the test so that it's executed inside the container. By the time the test framework calls your @Test annotated method, the test is running inside the container, giving us the possibility to work with container managed resources. Here's the complete test class with JUnit @Test methods.

@RunWith(org.jboss.arquillian.junit.Arquillian.class)
public class TemperatureConverterTestCase {

   @Deployment
   public static JavaArchive createTestArchive() {
      return Archives.create("test.jar", JavaArchive.class)
         .addClasses(TemperatureConverter.class, TemperatureConverterBean.class);
   }

   @EJB
   private TemperatureConverter converter;

   @Test
   public void shouldConvertToCelsius() {
      Assert.assertEquals(converter.convertToCelsius(32d), 0d);
      Assert.assertEquals(converter.convertToCelsius(212d), 100d);
   }

   @Test
   public void shouldConvertToFarenheit() {
      Assert.assertEquals(converter.convertToFarenheit(0d), 32d);
      Assert.assertEquals(converter.convertToFarenheit(100d), 212d);
   }
}

Note how we can use @EJB to inject the session bean from our deployment into the test case for use in our test method - neat!

The Arquillian TestEnricher SPI supports all the injection annotations from Java EE 6 - @EJB, @Resource and @Inject.

This example test case could run in GlassFish, JBoss AS or OpenEJB as there are no container specific code/configuration at all. The choice is yours. You could even test on multiple platforms!

I want to learn more, where should I go from here?

You can follow up with some in depth usage scenarios and tests described in these articles:

We also have reference documentation which walks you through the examples from Arquillian, and shows you how to create your own Arquillian test suite. You might also find the Javadoc useful, especially if you plan on adding support for another container. You can also check out the forums and more articles can be found on our community site. If your interested in chatting to us, please drop by #jbosstesting on irc.freenode.net

So, what's next?

Some of the things you can expect from Arquillian are:

  • Local run mode -- Sometimes, you don't want to run the test case inside the container itself. A local run mode will be added; a mode where your test controls the deployment but is not deployed as a part of it. This will give you the chance to run a test against, for example, JSF pages or RMI (testing for those nasty Non-Serializable / SessionClosed exceptions).
  • Multiple deployments controlled by same test -- Sometimes your micro deployment is not enough to test on its own and you want to package other components as part of the same deployment. For example, you need to test the interaction between two Web applications.
  • Support for method argument injection -- In the first alpha we only support field injection. In alpha 2 we will be extending the TestEnricher SPI to include support for method argument injection:
@Test
public void shouldWithdrawFromAccount(@EJB AccountManager manager) throws Exception
{
   ...
}
  • Test method interceptors -- Another planned enricher SPI is a test method interceptor. With this we can add support for transactions:
@Test
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void shouldWithdrawFromAccount(@EJB AccountManager manager) throws Exception
{
   ...
}
  • Convention over configuration -- The micro deployments should be as easy as possible to create, so adding support for common conventions should help speed up the test development. For example we can automatically add all classes in the same package as the test class to the deployment
  • Arquillian controlled resources -- Sometimes the container requires container specific configuration e.g, java.naming.\* parameters needed to create a InitialContext. If the test case has to explicitly deal with this, it places the burden for container portability back on the test case author. Arquillian will provide an extension point to add Arquillian created/managed resources:
// auto creation of InitialContext based on running container, remote or local.
@ArquillianResource
private InitialContext context;

// auto creation of URL to a specific deployed Servlet, including http port/ip etc.
@ArquillianResource(MyServlet.class)
private URL myServletURL;

// the bundle context of a deployed osgi bundle
@ArquillianResource
private BundleContext context;
  • Add support for more containers -- We will plan to support more containers! Currently we have planned: GlassFish 3 (as a remote container), Jetty, Tomcat, Resin, Felix OSGI. (Hey Spring guys, you're welcome to join in too!)
  • Third party integrations -- In the spirit of ease of development, we integrate with existing test frameworks as much as possible, but we are always keen to learn of new frameworks we can integrate with. We already plan to support Selenium for example.
  • Support for other build tools -- Arquillian Alpha1 comes with Maven support. In upcoming releases, we will distribute builds targeted toward other build tools like Ant and Gradle (that shout out is for our resident Gradle expert, Jason Porter).
  • A project page, logo and artwork -- All good things must look good. That's why the JBoss.org design team is hard at work putting together artwork for the Arquillian project page. Stay tuned!

Where can I see Arquillian in use?

Arquillian is a new framework, but it's going to be put right to work as the workhorse to test all the Seam 3 modules. It will also be our recommended solution for testing your Seam application. (We'd love to see the community try it out for testing Seam 2 applications). We'll also replace the current core of the JSR-299 CDI TCK with Arquillian, likely for the 1.1 version of the TCK. (To provide a little history, Arquillian originated from the JBoss Test Harness that was developed by Pete Muir as the foundation of the CDI TCK).

If you have any thoughts on these ideas, or would like to suggest some new avenues we should explore, please contact us on the Arquillian Dev forum.

And, what's open source with out the community?!

A big thanks to the Arquillian and ShrinkWrap community for helping out on this release by being early adopters, joining in on community meetings, general discussions and writing blogs, articles and patches. In alphabetical order: Dan Allen, Steven Boscarine, German Escobar, Jordan Ganoff, Ken Gullaksen, Pete Muir, Jason Porter, Andrew Lee Rubinger. You guys rock!

[ JIRA ] | [ SPI Javadoc, API Javadoc ] | [ Reference Guide ] | [ Release Notes ] | [ Maven Artifacts ]

14 comments:
11. Mar 2010, 03:11 CET | Link
Jeremy Norris | jnorris(AT)pattern73.com

Nice work guys! This project looks very well thought out.

ReplyQuote
 
11. Mar 2010, 12:26 CET | Link

Congrats on this! I hope this brings a whole host of EE developers out of the dark ages w/r/t testing practices. This is cool stuff!

In addition to the examples we have, (and those that are forthcoming,) I think it would be appropriate to provide a full test suite that includes unit tests (not using Arquillian as well) because I think there are a host of developers new to this concept (or not used to it in the EJB space) that could benefit from seeing when it's appropriate to use Arquillian and when its not, and how one should go about it.

I find when developers first start writing test code against EJBs they start writing integration tests, and the test code grows large and procedural and becomes a pain to maintain. Smaller tests are easier to read and maintain. It's going to be hard for people to adopt the right usage if they don't understand that, I think. Just my $0.02.

 
12. Mar 2010, 01:03 CET | Link
Chris Wash wrote on Mar 11, 2010 06:26:
In addition to the examples we have, (and those that are forthcoming,) I think it would be appropriate to provide a full test suite that includes unit tests (not using Arquillian as well) because I think there are a host of developers new to this concept (or not used to it in the EJB space) that could benefit from seeing when it's appropriate to use Arquillian and when its not, and how one should go about it. I find when developers first start writing test code against EJBs they start writing integration tests, and the test code grows large and procedural and becomes a pain to maintain. Smaller tests are easier to read and maintain. It's going to be hard for people to adopt the right usage if they don't understand that, I think. Just my $0.02.

Absolutely. This is ALR's area and you can expect him to address this very issue in his EJB 3.1 book, for which all the examples are available.

 
12. Mar 2010, 23:28 CET | Link
Juergen Zimmermann

Arquillian looks very promising! The reference doesn't mention no-interface session beans http://docs.jboss.org/arquillian/reference/1.0.0.Alpha1/en-US/html/enrichment.html . Do you have a coarse estimation when no-interface beans will be supported by Arquillian ?

 
14. Mar 2010, 03:39 CET | Link
John Ament

So I couldn't help but notice that there were no download links and looks like it's not in maven. Need to build it locally I suppose?

 
14. Mar 2010, 14:21 CET | Link

There is no dist created at the moment, but the Maven artifacts can be found in the JBoss.org repository.

 
01. Jun 2014, 09:00 CET | Link

It is really a good testing tool

 
29. Aug 2014, 06:37 CET | Link
obat gondok herbal k-muricata

I been very encouraged to find this website. I desired to warm regards with this special study. I certainly savored every it and I've you bookmarked to look at new things you publish. obat gondok herbal k-muricata

 
26. Sep 2014, 09:46 CET | Link
obat flek paru paru

Obat Herbal Alami Sakit Flek Paru-paru amazon Jus Kulit Manggis obat flek paru paru

 
06. Oct 2014, 14:38 CET | Link

This is what exactly I wanted, the information was overall very useful for me, Many thanks. Quality bathroom Renovations Sydney

 
11. Oct 2014, 03:51 CET | Link

This is really my very first time here, great looking blog. I found a lot of interesting things inside your blog especially its discussion. From all the remarks in your articles, it appears like this is really a extremely popular website. Keep up the truly amazing work. TV Bangka Belitung.

31. Oct 2014, 20:12 CET | Link
Free sex cams

The Best Sex Cams are live adult sex chats that are the most popular adult chat on the internet today. Pick a performer and let your fantasy go wild. For more info, visit my website http://www.Thebestsexcams.com/ ...

31. Oct 2014, 20:12 CET | Link
bondage

A new adult forum with original sex stories, sexual role play, discussions, chat, and more. Please visit site http://forbiddenforcedfantasy.com ...

31. Oct 2014, 20:13 CET | Link
click here | sdfsd(AT)sdffd.com
https://www.rebelmouse.com/restoremyvisiontodayreviews/

Restore My Vision Today: Dr. Sen And Samantha Pearson Reveal A Breakthrough, Step-By-Step System To Achieve 20/20 Vision And Help Cure Myopia, Hyperopia, Presbyopia, And Most Other Visual Problems In As Little As 2 Weeks... Written for consumers by a consumer, this fan site includes a fun and informative Restore My Vision Today review, ebook FAQ, and PDF download guide that provides an insider's look at the program and answers frequently asked questions about Dr. Sen and Samantha Pearson's unique and highly popular vision training guide. Please click here site https://www.rebelmouse.com/restoremyvisiontodayreviews/ ...

Post Comment