Unit Test Is Not Integration Test

Unit tests are clearly defined:

“In computer programming, unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual function or procedure. In object-oriented programming a unit is usually a method…” [http://en.wikipedia.org/wiki/Unit_testing].

Applying this definition to Java EE 6 context means you have to mock out the whole environment (=all classes and Java EE resources in particular). The EntityManager is going to be completely mocked-out as well:

class PersistentHitStoreTest extends JUnitSuite with MockitoSugar with ShouldMatchersForJUnit{
  var cut:PersistentHitStore =_
  def setUp: Unit = {
    cut = new PersistentHitStore();
  def persistCacheDeletesCache:Unit = {
    cut.em = mock[EntityManager]

[sample from x-ray]
If you are using maven, see Trouble With Crippled Java EE 6 APIs in Maven Repository And The Solution and A Natural Separation of JUnit Tests in Maven (3).

One of the FAQs: "How to unit test Java EE 6 applications" is extremely easy to answer: there is no difference between unit testing of Java SE and Java EE 6 applications :-).

[See also page 109 "Unit Test Is Not Integration Test" in Real World Java EE Night Hacks--Dissecting the Business Tier.]

NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns


make sure you check out FunSuite and BeforeAndAfter traits as well, for me they makes tests both more natural and more expressive.. welcome to scala :)

Posted by Kristof Jozsa on June 27, 2011 at 06:55 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments