Java Reference
In-Depth Information
Arquillian is a sophisticated integrated testing tool. Think of it as a wrapper around the em-
bedded EJBContainer . It presents a simpler interface for configuring and running the
embedded EJBContainer . This allows your integration testing to focus more on testing
the EJBs than on resource management for running the integration tests.
Although integration testing takes the testing of your code a step further than unit testing, it
still relies on mimicking the external resources your application depends on. To fully com-
plete testing of your application, you need functional testing.
Functional testing
Functional testing is a testing strategy usually carried out by a separate testing team within
the organization. At this level, the application is fully deployed into a real environment.
The testing team will use a combination of automated and manual testing to check that the
application is working properly. Because functional testing is typically outside the respons-
ibility of the development team, we won't cover functional testing in any more detail. The
remainder of this chapter will focus on unit testing and integration testing.
15.2. Unit testing EJBs
Let's dive into an example and see how to use JUnit and Mockito to unit test an EJB. List-
ing 15.1 is a simple stateless session bean in the ActionBazaar application. Its purpose is to
determine what discount should be applied to a member's purchase. The discount to apply
is determined by a simple business rule based on the membership level the member has
purchased. Testing DiscountManagerBean is vital to Action-Bazaar to prevent crazy
discounts that may threaten the business.
If you download the code for this chapter, DiscountManagerBean is located in the
chapter15-ejb Maven submodule. Let's take a look at the various parts of the bean so
you'll know how to construct your unit tests.
Search WWH ::




Custom Search