Inject CDI bean in Junit script test

I have an application running on JBoss AS 7.1.1. This application uses some CDI specification resources like interceptors, injections, etc. The architecture of my application is very simple with the structure below:

view (xhtml and facelets)

controller (managed beans with @Named except ViewScoped)

model (divided into two levels, service and Tao)

service (with @Stateless annotation, here I use the interceptor that I created to manage database transactions because I use my own JDBC)

tao

I need to create several scripts to test the service level of an application by introducing a service implementation and calling business methods.

I believe this architecture is very common. Sorry for my english.

Can someone help me please?

Thank!

+3
source share
1 answer

If you want to test your full container, you probably want Arquillian . If you want to perform unit testing with mocks, run a standalone container for welding in your test using a weld.

new Weld().initialize().instance().select(YourClassName.class).get();

You can replace your mock objects using alternatives in beans.xml. You can also use the CDI-Unit , which simplifies the process a bit.

+3
source

All Articles