开发者

How to inject PesistenceContext in my tests using EJB 3.1?

Hi in Spring it's easy to do so... as Spring doesn't require an Container, you just add an @autowired and it's done.

But in EJB 3.1, using @Inject is useless if the app is not deployed... I am getting nullpointer and it's looks logical to get them, because of the lack of a container during tests.

How can I inject a PersistenceContext into my TESTS for example using only EJB 3.1 features ? is it possible witho开发者_Go百科ut a container ?


Take a look at the Arquillian project. It allows outside container testing of Java EE applications.

http://www.jboss.org/arquillian


Glassfish 3.x will allow you to embed the container and run your tests. Here's a few links that should get you going:

  • Unit Testing EJBs and JPA with Embeddable GlassFish
  • JPA Unit testing with the GlassFish 3 embedded EJB container
  • Adam Bien's Weblog
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜