Java Reference
In-Depth Information
for them. Integration tests do a more convincing job of demonstrating how the sys-
tem works (especially to nonprogrammers), at least to the extent that the integration
test environment resembles the production environment.
Instruments for testing
As you can imagine, each kind of testing uses a different approach; for example, as
far as unit testing is concerned, the most common way to test is by means of mock
objects . If you have an object whose methods you want to test, and if these meth-
ods depend on some other object, you can create a mock of the dependency rather
than an actual instance of that dependency. This allows you to test your object in
isolation.
As an example, one common use case might be in an MVC application, where you
have a DAO ( data access objects ) layer and a controller that performs business
logic. If you'd like to unit test the controller, and the controller has a dependency on a
DAO layer, you can make a mock of the DAO that will return dummy objects to your
controller.
This kind of approach, although very immediate to understand and put in to practice,
has several limitations. Firstly, it relegates you into an artificial environment where
you will often make invalid assumptions about the behavior and stability of that en-
vironment.
Secondly, you will end up with a hard-to-maintain mock library that will allow your
tests to pass and give you the warm feeling of having done a great job.
So, even if mock objects may still provide some benefits for starting up systems,
where you don't have full implementations of a particular subsystem, you should
stick, as close as possible, to the target environment that the code is supposed to
run in.
Arquillian is a platform that simplifies integration testing for Java middleware. It deals
with all the plumbing of container management, deployment, and framework initializ-
ation so you can focus on the task of writing your tests—real tests. Arquillian minim-
izes the burden on you—the developer—by covering aspects surrounding test exe-
cution; some of these aspects are as follows:
• Managing the life cycle of the container (start/stop)
Search WWH ::




Custom Search