A new article by Java Champion Adam Bien, now up on otn/java, titled “Integration Testing for Java EE,” explores the intricacies of integration testing, which is done after a successful execution of unit tests, which however, will often fail. According to Bien, unit tests are fast and fine-grained while integration tests are slow and coarse-grained.
From the article:
“Testing everything inside an embedded container is convenient but unproductive. Java EE 6 components are annotated Plain Old Java Objects (POJOs) and can be easily unit tested and mocked out (see my previous article, “Unit Testing for Java EE.") with Java SE tools such as JUnit, TestNG, or Mockito. Using an embedded container to test your business logic is not only unproductive, but it is also conceptually wrong. Unit tests should validate your business logic, not the container behavior. Also, the majority of integration tests could be easily performed with a local EntityManager (see Listing 1) or a mocked-out container infrastructure. Only a fraction of all integration tests can be beneficially implemented with embeddable containers or test frameworks such as Arquillian.”
Read the complete article here