I use Deltaspike CdiControl to start up the CDI container for my unit tests. That works fine but there is a problem: If I use this approach for Maven web app the beans.xml
end up in src/main/webapp/WEB-INF
. That means it is not in the META-INF
directory in the target folder during unit tests.
Since the unit tests itself are not a webapp
but a Java SE run the WEB-INF
directory is ignored. I can fix this by adding a second beans.xml
to META-INF
and/or copying the existing beans.xml
to the right folder for unit tests. But this would mean I have to exclude it from the war manually so it seems a bit hackish.
Putting a beans.xml
into src/test/resources/META-INF
does not work because it will only allow the CDI components in target/test-classes
to be detected.
This seems such a common problem that I assume somebody must have run into this before? Or is everybody having a separate Maven module for the components and/or the unit tests?
beans.xml
around in/target
for test execution part. But I would rather advice to take advantage of Weld's ability to disable discovery (nobeans.xml
needed) and then only add few beans you need in each given test. If it's truly unit testing, you don't need all of them anyway. You can also look at weld-junit if you need a simple tool for Weld junit testing. – Glottochronologybeans.xml
you wish to (amongst other things). But that depends on your app (SE,EE?) and so forth. I am just tossing ideas around.... – Glottochronology