This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Testing and the fly likes Using Junit to test MDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Using Junit to test MDB" Watch "Using Junit to test MDB" New topic

Using Junit to test MDB

Sachin Navari

Joined: Oct 07, 2005
Posts: 2
I am newbie to Junit and i am writng a Test case for a MDB. BBasically i have to post a message and later check the records in couple of tables to check if the logic is executed correctly to populate the right tables.

Can any body direct me to some pointers.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
The best way I know to do this is to extract the logic into a POJO which the MDB delegates to. You can then test the POJO as usual.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Or, by simply instantiating your MDB class and calling the onMessage() method on it yourself.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: Using Junit to test MDB
It's not a secret anymore!