A JUnit 5 extension for testing JSR-330 components. Annotate a test class with @PlexusTest and your
@Inject fields are populated from a container built for that test.
Maintained. Small and stable — it exists so the other projects here can test their components without each inventing the same fixture.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-testing</artifactId>
<scope>test</scope>
</dependency>Check the badge above for the current version.
import javax.inject.Inject;
import org.codehaus.plexus.testing.PlexusTest;
import org.junit.jupiter.api.Test;
@PlexusTest
class MyComponentTest {
@Inject
MyComponent component;
@Test
void itWorks() {
assertNotNull( component );
}
}A test class can customise the container by implementing
PlexusTestConfiguration;
every method has a default, so implement only the ones you need.
How the container is built:
- A new container is created for each test method, and it is closed after the test.
- It scans the Sisu index (
META-INF/sisu/javax.inject.Named) and wires@Injectfields of the test instance, including those of@Nestedclasses. - If a resource named after the test class exists (
org/foo/FunTest.xmlfororg.foo.FunTest, also looked up for its superclasses), it is used as the Plexus container configuration. PlexusExtension.getBasedir(),getTestFile(path)andgetTestPath(path)resolve paths against thebasedirsystem property, or the working directory when it is not set. Theplexus.homecontext entry defaults totarget/plexus-homeunder it.
The project site shows the full examples, compiled from this repository's own tests.
Java 8 or later, JUnit 5, and javax.inject for the components under test (this artifact does not bring it). Building the project needs Maven 3.9.0 or later.
Conventions for contributors and agents are in AGENTS.md; see also
CONTRIBUTING.md. In short:
mvn verify builds, and run mvn spotless:apply before pushing or CI will fail on formatting.
Please report security vulnerabilities privately — see SECURITY.md, not a public issue.