Search code examples
javaunit-testingtestingjunitcdi

Is it possible to grab the CDI container from inside a JUnit test?


Using CDI, is it possible to grab the CDI container?

I was creating a unit test and wanted to access the CDI container from inside the JUnit test.


Solution

  • Since CDI 1.1, you can use CDI.current(). It returns the CDI instance that provides access to the current container.

    Depending on the tests you are writting, you could consider Arquillian.