Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bootstrap weld-se in a JUnit test
    primarykey
    data
    text
    <p>I have a maven project for unit tests and would like to use CDI. I've put the weld-se dependency in pom.xml like this : </p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;4.10&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.jboss.weld.se&lt;/groupId&gt; &lt;artifactId&gt;weld-se&lt;/artifactId&gt; &lt;version&gt;1.1.8.Final&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javax.enterprise&lt;/groupId&gt; &lt;artifactId&gt;cdi-api&lt;/artifactId&gt; &lt;version&gt;1.0-SP3&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>I'm bootstrapping weld in a JUnit test runner : </p> <pre><code>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; } } </code></pre> <p>And a unit test that uses this runner. The test is injecting an application scoped bean. The problem is that weld cannot initialize because of an "Unsatisfied dependency" on the only injection point, as if my application scoped bean was totally unknown to weld. But that bean is in src/test/java/... with my test (but in another java package).</p> <p>I have an empty beans.xml in src/test/resources.</p> <p>I noticed weld gives warnings when starting but I don't think these are the cause of my problem : </p> <pre><code>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 </code></pre> <p>Can someone help me with that ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload