Weld CDI : Using @Alternative @Singleton <p>I have a Producers class annotated with <code>@Singleton</code>, containing a method annotated with <code>@Produces</code>.</p> <p>I want to write unit test using an alternative of this method, but can't manage to do it. here's a summary of my code :</p> <pre><code>package fr.easycompany.easywrite.tools.injection; @Singleton public class Producers { @Produces @Named(PREFERENCES_FILE_NAMED) public String producePreferenceFileName(){ return "preferences.xml"; } } </code></pre> <p>And my Alternative :</p> <pre><code>package fr.easycompany.easywrite.tools.injection; @Singleton @Alternative public class ProducersAlternative { @Produces @Named(PREFERENCES_FILE_NAMED) public String producePreferenceFileName(){ return "preferences_test.xml"; } } </code></pre> <p>I also created a beans.xml in src/test/resources/META-INF with the following content</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:weld="http://jboss.org/schema/weld/beans" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd"&gt; &lt;alternatives&gt; &lt;class&gt;fr.easycompany.easywrite.tools.injection.ProducersAlternative&lt;/class&gt; &lt;/alternatives&gt; &lt;/beans&gt; </code></pre> <p>At the execution, it's always <code>Producers#producePreferenceFileName()</code> which is called. Why is it not <code>ProducersAlternative</code>'s method ? Is it impossible to have an alternative of a singleton injected class ?</p>