Skip navigation
2011

Hi all.

This is my first post on this blog. I am planning to write things about different aspects of software design/architecture, that I face during my work  expriences. Should be fun! Hope you also enjoy the posts.

 

OK. first post goes for Web application's unit test/integration test. I separate it to two parts. In first part, I want to explain some basic concepts, and in second part, I will explain about "Arquillian", which is the newest framework by JBoss for web application's test.

 

Suppose we have a web application, and we want to create some unit test/integration test items for it. If your application is windows application, you just need to create some JUnit or TestNG test cases/suites (for Java language), and then you are done. But, if you are dealing with web applications, I think you will agree that it is not as easy as it seems to create/test such test cases. Your test cases need to run inside the web application container, in order to be able to access to your application's database, message queue, application context, and other business logic classes that their life-cycle is managed by container.

 

I think the problem is clear, but, what is the solution? Basically, there are two approaches for dealing with this problem.

 

  1. Mock Object Test Approach: "Mock" means a program that simulates the web application container. Mock programs hide the difficulty of dealing with actual web application containers, and make the test easier. But, on the other side, they have the problem that your test is not running in the acual container, and you are not sure the result of test will be exactly same when you run it in actual environment. Also, if you have complicated setting files or use some speical libraries, you may face some compile/setup/run errors. If you want to use this approach, for Java programming language, you can use JMock, EasyMock, Mockito, Mockrunner, and many others. You can use some other mock test tools in this link and link2.
  2. In-Container Test Approach: As it is obvious from the name, test cases are deployed and run inside the container. The idea is straightforward, but, the difficulty is how to deploy/run the test cases inside web application. For this approach, you can use frameworks, like: Apache Cactus, JUnitEE, and JBoss Arquillian.

 

According to the requirements of your project, you need to select a framework. For me, since I wanted to run my tests in actual container, I decided to use In-Container test approach. I think it should be a logical selection for many of you too.

 

As you can see in official Apache Cactus's homepage, this project has been retired from Apache projects on 2011/8/5, and there will not be any extension/development in this project. Honestly, I didn't select the JUnitEE, since this project's homepage is not updated for long time. Even their EJB's sample test is not updated for EJB 3.0 and it is EJB 2.0. And, finally, I selected JBoss Arquillian for In-Container test of web application. I selected it not because there is no other option, but actually because it is well-designed and easy-to-use, and it simplifies all the difficult tasks of archeiving/deploy/test/undeploy of test cases into container (Arquillain interally uses JBoss ShrinkWarp for archeiving/deploy/undeploy into container).

 

In part 2, I will explain about JBoss Arquillian and how to use it to unit test the web applications.