You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Mark Lybarger <Ma...@CBC-Companies.com> on 2004/04/21 14:39:50 UTC
how to test Session Facade without database
I'd like to be able to test my Stateless Session EJB's w/o relying on data in the database. (initially... later, i'd like to remove dependancy on a remote tuxedo call we also do). What's the best way to do this? Mock the database? Hypersonic database for testing?
Our DAO layer is similar to the torque peer setup. We have EJBs that call other EJB's or that call static methods on Peer classes. The Peer classes return DTOs filled with data from the db. All database access is done through these Peer classes. I've read in some XP book someplace how to test database methods by mocking the database objects, (record set mocks, connection mocks), but I'm just not sure how that would work out if we're not directly testing the Peer classes, but testing the EJB interface itself. We're implementing the session facade pattern now (moving code from turbine actions) to make functionality more available to other processes. And IMO, having testing on this functionality is essential. Any insights would be most appreciated.
Thanks!
Mark
Re: how to test Session Facade without database
Posted by "J. B. Rainsberger" <jb...@rogers.com>.
Mark Lybarger wrote:
> I'd like to be able to test my Stateless Session EJB's w/o relying on data in the database. (initially... later, i'd like to remove dependancy on a remote tuxedo call we also do). What's the best way to do this? Mock the database? Hypersonic database for testing?
My usual approach is to mock the database by a three step approach:
1. Centralize data access as much as possible
2. Extract Interface
3. Mock the new interface with EasyMock/jMock
> Our DAO layer is similar to the torque peer setup. We have EJBs that call other EJB's or that call static methods on Peer classes. The Peer classes return DTOs filled with data from the db. All database access is done through these Peer classes. I've read in some XP book someplace how to test database methods by mocking the database objects, (record set mocks, connection mocks), but I'm just not sure how that would work out if we're not directly testing the Peer classes, but testing the EJB interface itself. We're implementing the session facade pattern now (moving code from turbine actions) to make functionality more available to other processes. And IMO, having testing on this functionality is essential. Any insights would be most appreciated.
Get rid of the class-level (static) methods immediately, and if you can,
quickly. They provide no value unless you consider excessive coupling
valuable. :)
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand