• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB3 testing with JUnit4

 
bhama kumaran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34214
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
bhama kumaran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34214
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you running your test? If you use a server side framework, like Cactus, it can access the EJB.
 
bhama kumaran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my knowlege junit can't be used to test applications...

You will need
 
Manuel Alberto Quero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use "Cactus" to test your enterprise components.

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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic