This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EJB3 testing with JUnit4

 
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:cry:
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • 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
Posts: 40035
809
Eclipse IDE VI Editor Java
  • 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.
 
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
 
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/


 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic