This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Using Junit to test MDB" Watch "Using Junit to test MDB" New topic
Author

Using Junit to test MDB

Sachin Navari
Greenhorn

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.

Thx,
Sachin
Ilja Preuss
author
Sheriff

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Using Junit to test MDB