I have a maven project for unit tests and would like to use CDI. I put the weld dependency in pom.xml as follows:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> <dependency> <groupId>org.jboss.weld.se</groupId> <artifactId>weld-se</artifactId> <version>1.1.8.Final</version> </dependency> <dependency> <groupId>javax.enterprise</groupId> <artifactId>cdi-api</artifactId> <version>1.0-SP3</version> </dependency>
I load the weld in a JUnit test runner:
public class WeldJUnit4Runner extends BlockJUnit4ClassRunner { private final Class klass; private final Weld weld; private final WeldContainer container; public WeldJUnit4Runner(final Class klass) throws InitializationError { super(klass); this.klass = klass; this.weld = new Weld(); this.container = weld.initialize(); } @Override protected Object createTest() throws Exception { final Object test = container.instance().select(klass).get(); return test; } }
And the unit test that this runner uses. The test introduces the scope of the bean. The problem is that the weld cannot be initialized due to the “Unsatisfied dependency” on a single injection point, as if my scope of the bean was completely unknown for welding. But this bean is in src / test / java / ... with my test (but in a different java package).
I have an empty beans.xml in src / test / resources.
I noticed that at startup the welder warns, but I do not think this is the cause of my problem:
604 [main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled 605 [main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
Can someone help me?
source share