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.]

Comments:

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
https://hg.kenai.com/hg/javaee-patterns~hg

Greetings Thomas

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

Hi Thomas,

hg clone https://hg.kenai.com/hg/javaee-patterns~hg

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

thanks for your interest!,

adam

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.

Cheers!

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 (http://monkeyisland.pl/2008/02/24/can-i-test-what-i-want-please/), 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?

Greetings
Torsten

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

@Mikolaj,

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!,

adam

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

@Torsten,

IMHO private, injected, fields should be considered harmful: http://www.adam-bien.com/roller/abien/entry/inject_with_package_private_fields

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

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

thanks,

adam

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
License