Myths, Oracles and Mockitos--How To Unit Test Java EE 6 Applications (Free Article)

The free article Unit Testing for Java EE describes unit testing and mocking of Java EE 6 (CDI, JPA and EJB) applications. The subsequent articles will focus on integration and load testing.

[See also page 109 "Unit Test Is Not Integration Test" and page 151 "Java EE Loves Stress and Laughs About JUnit" in Real World Java EE Night Hacks--Dissecting the Business Tier.]


Hi Adam, Great post!

But how can i checkout the sources from kenai? i tried the checkout url but it seems to be no svn repository

Greetings Thomas

Posted by Thomas on August 23, 2011 at 04:23 PM CEST #

Hi Thomas,

hg clone

It is not SVN. OpenSource projects should be fun :-)

thanks for your interest!,


Posted by Adam Bien on August 23, 2011 at 05:17 PM CEST #

Great article! Once again it shows how simple developing and testing Java EE applications is.


Posted by PedroKowalski on August 23, 2011 at 05:21 PM CEST #

Adam, I have a general question considering writing unit tests. What is your opinion on veryfing that some interactions DIDN'T happen? I know that one of the motivations behind Mockito is that testing irrelevant interactions doesn't make sense (, but I wonder if really calling verifyNoMoreInteractions() should be considered harmful? :)

Posted by Mikolaj on August 23, 2011 at 06:39 PM CEST #

Hi Adam,
i like your article. But in my project there's the convention to declare all injected fields private.
Is it usual to declare the fields friendly, like in your article?
Are there other reasons than better testability?


Posted by torsten on August 24, 2011 at 12:04 PM CEST #


sometimes it is crucial to verify that some invocations did NOT happen.

In a project with custom persistence I used Mockito's verify / none() methods to assert that only idempotent invocations were replicated and the "getters" were not. It was extremely easy to implement that with Mockito,

thanks for your comment!,


Posted by Adam Bien on August 24, 2011 at 12:54 PM CEST #


IMHO private, injected, fields should be considered harmful:

You should always ask: "Why not?" and expect a reasonable answer.

If there is no reasonable answer, there should be also no rule :-)



Posted by Adam Bien on August 24, 2011 at 12:57 PM CEST #

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