I use Junit5 test platform with Weld WeldJunit5AutoExtension.class for DI in my Junit5 tests.
Links for the libraries: https://github.com/junit-team/junit5 https://github.com/weld/weld-junit
The main pom.xml contains:
<properties>
<version.weld-junit>1.3.1.Final</version.weld-junit>
<version.junit.jupiter>5.3.2</version.junit.jupiter>
<version.junit.vintage>5.3.2</version.junit.vintage>
</properties>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
<version>${version.weld-junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit.jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit.jupiter}</version>
<scope>test</scope>
</dependency>
Simple example of test class
import a.b
import c.d
import e.f
import g.h
@EnableAutoWeld
@AddPackages(b.class, d.class, f.class. h.class)
class MyTest {
@Inject
private B b;
@Inject
private D d;
@Inject
private F f;
@Inject
private H h;
}
Is there a posibility to have a full discovery automatic mode without additional annotations other than @Enable... in general. Before Weld extension for Junit5 i've use a CdiRunner.class for Junit4 and all injections were fully automatic. Sometimes I have to add an annotation.
In other word I want to discover not only a test package classes but add for example all dependencies from other modules to Weld container to avoid 'annotation hell'.
Aucun commentaire:
Enregistrer un commentaire