cdicdi-unit

How to exclude classes from scanning with CDI-unit?


I am running tests with CDI-unit runner and want some classes to be excluded (because they act on CDI events). I tried beans.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee">
    <scan>
        <exclude name="com.mypackage.**"/>
    </scan> 

</beans>

but CDI-unit seems to be ignoring it. So what is the correct way to exclude the classes with CDI-unit?


Solution

  • You may provide an alternative of the class you want to exclude, so that the alternative test class is used instead. With CDI Unit you turn on your alternative with @ActivatedAlternatives on your tests, or globally with @ProducesAlternative on your test producer. See more here: http://jglue.org/cdi-unit-user-guide/#alternatives

    AFAIK, CDI Unit does not directly support exclusion of beans. But in most cases using alternatives is sufficient.