Testing an EJB with JUnit

后端 未结 4 1611
天命终不由人
天命终不由人 2020-11-30 18:27

How should I test an EJB 3.1 which gets an instance of EntityManager injected?

A possible EJB:

@Stateless
@LocalBean
public class CommentService {

          


        
4条回答
  •  执念已碎
    2020-11-30 19:09

    It's possible to write unit tests that run against a container, but the caveat is that the container/appserver has to be up. Since that's not really practical, the general approach is to use a "mock" container to run your unit tests against. For that, check out JUnitEE or ejb3unit:

    junitee

    ejb3unit

提交回复
热议问题