aspose file tools*
The moose likes Testing and the fly likes EJB3 testing with JUnit4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "EJB3 testing with JUnit4 " Watch "EJB3 testing with JUnit4 " New topic
Author

EJB3 testing with JUnit4

bhama kumaran
Greenhorn

Joined: Aug 18, 2009
Posts: 14
Hi,
How can we get EntityManager in JUnit test class.I am trying to get it using the below code, but it returning null.

When I run the above as JUnit test, it fails throwing :

Please help.javascript:emoticon
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30960
    
158

First of all, you are using a mix of JUnit 3.8 and 4.0. This may cause you problems. The only line in your code that is 3.8 is this one. You might want to remove the "extends."


Now on to your problem - you are running your JUnit test a standalone program, not an EJB. This means it isn't a session bean even though you have the annotation. Which in tern means things aren't injected.

What are you actually trying to test? A session bean? Something else?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
bhama kumaran
Greenhorn

Joined: Aug 18, 2009
Posts: 14
I am trying to test session bean. I am trying to get entitymanager in a stateless session bean.How do I do it?
bhama kumaran
Greenhorn

Joined: Aug 18, 2009
Posts: 14
I am trying to do JuNite testing on session bean. I am trying to get entitymanager.How do I do it?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30960
    
158

How are you running your test? If you use a server side framework, like Cactus, it can access the EJB.
bhama kumaran
Greenhorn

Joined: Aug 18, 2009
Posts: 14
No I am not using any server side framework. I am working on RAD 7.5 with WAS 7. Can unit test my DAO classes using Junit here.
I was trying to get the entitymanager in a junit test class. I tried also injecting the entitymanager and making the test class as session. But I still get entitymanager as null. Is there is any way I can unit test ejb's from inside the container.
Kinjal Dave
Greenhorn

Joined: Nov 02, 2009
Posts: 1
As per my knowlege junit can't be used to test applications...

You will need
Manuel Alberto Quero
Ranch Hand

Joined: Jul 17, 2009
Posts: 31
You could also use "Cactus" to test your enterprise components.

http://jakarta.apache.org/cactus/


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB3 testing with JUnit4