I have created several Entity Beans that require unit test cases. Following the Data Transfer Object Factory pattern, we are only exposing local interfaces to our Entity beans.
- Posted by: Ian edmondstone
- Posted on: November 05 2002 19:21 EST
I have two questions.
Firstly, what is the general conscenus regarding testing of generated code (namely setters/getters) on Entity beans?
Secondly, as the interfaces are local, are there test tools available that auto generate a session facade with a remote interface to test the Entity bean? Or is there a better way to test local interfaces?
Any help would be greatly appreciated.
- EJB Local Interface Unit Testing by David Jones on November 05 2002 19:50 EST
- EJB Local Interface Unit Testing by David Jones on November 05 2002 19:56 EST
- EJB Local Interface Unit Testing by Rod Johnson on November 06 2002 13:37 EST
PS. IMHO I would recommend that you completely test you Entity Beans including getters and setter. To be honest how else are you going to know you have finished your implementation?
Ian, as David points out, you need to test any EJBs with local interfaces within the same app server instance. This means using something like Cactus that allows you to deploy your tests along with the EJBs you need to test. Cactus works pretty well, but this is still relatively complex.
I probably wouldn't bother testing your getters and setters. They can be expected to work: problems are only likely to arise in more complex usage. You presumably have a session facade that uses the entities? In this case, why don't you test the business methods on this?
One of the main drawbacks of EJBs, in my opinion, is that they're relatively hard to test, because they're so dependent on container services. It's harder to write and slower to deploy test cases, meaning they're less likely to get written and executed.
You might be interested in the chapter on testing in my new book, Expert One-On-One J2EE Design and Development.
Thanks Rod. I do not have a prob testing the business logic, including finder methods within the entity bean. I am in two minds regarding testing the getters/setters. My current project insists all methods are tested, including getters/setters.
JBuilder8, which is now out, incorporates Cactus for EJB testing, which I hope is a simple wizard based config.
I do have a facade using the entities, however the interface to the facade is also local, as we are following Floyds Data Object Factory Pattern (which is excellent).
I havent seen your book as yet, however Oz is usually a few months behind when it comes to publications.
Thanks to everyone for their feedback.