• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB 3 and test-driven development  RSS feed

 
J. B. Rainsberger
author
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious about the relationship between EJB 3 and the test-driven development community, or even the lightweight Java community, in general. It looks like EJB 3 was influenced to a degree by the ideas coming out of those communities, so if the authors have any story they'd care to share about that, I'd like to read it, positive or negative.

Also, I'm curious about the odd style of dependency injection that EJB 3 appears to have adopted. I admit that I've only looked at it briefly, but it appears not to have what I consider the true benefit of dependency injection, and that is an easy way to substitute test doubles for EJB dependencies to make testing easier. I can see that the annotation-style injection removes the need for duplicating all the JNDI lookup code, but is that all it does?

Thanks. After years of telling people how to work around EJB, it's nice to see the potential for not having to give out that advice any more.

Take care.
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We absolutely were influenced by TDD, and I even did some presentations some time ago on how EJB 3.0 allowed and promoted TDD. We do mention TDD in the book (have an entire chapter on testing) and discuss unit tests and integration tests, in addition to functional and acceptance tests.

When it comes to injection in EJB 3 I don't belive that there is any real loss of substitutability as a result of using annotations. An EJB is injected into a member that is defined to be of some type of business interface. The implementation of that business interface may be whatever class is supplied as the deployed impl class, so it may change without any change to the class being injected. A typical case, though, may be that in TDD you may not even be running in the EJB container, so you create a test injection method to do the injection for you, and again, you need not change the injected class. EJB 3 allows both annotation and XML injection, anyway, though, so if none of this makes any sense to somebody then they can alsways just resort to using XML, like Spring and others have traditionally done. Annotations are helpful not only for removing the lookup code, but also for being able to define the dependencies locally in the code, ie, where the dependency actually exists. Thre are a number of advantages to being able to do this, not the least of which is to be able to define it in Java and not have to go into XML.

Thanks. After years of telling people how to work around EJB, it's nice to see the potential for not having to give out that advice any more.


That was the goal :-)

-Mike
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In TDD, how do I inject the dependency object ? If I am testing outside the EJB container who will provide the persistence service.
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradeep,

You might want to take a look at this.

From the conclusion of the article of Lucas Jellema:
It turns out to be very straightforward to get EJB 3.0 Persikstence to work, outside of a container. The concepts are - not surprisingly- pretty familiar: you create POJO Domain Objects, you specify how they map to table and columns and you make use of some sort of session or service or manager object to invoke persistency services. This is no different from frameworks like Hibernate or Toplink. From what I have seen already from the more advanced mapping facilities in EJB 3.0, I am pretty sure we can most of the persistency functionality we need. Not all of it, but then again, no framework provides all I need or desire.


Kind regards,

Gian
[ August 16, 2006: Message edited by: Gian Franco Casula ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!