Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Weld Testing lets you run JUnit tests against a real CDI container, so you can verify injection and other container-managed behavior without starting a full application server. It supports JUnit 4, JUnit Jupiter, and Spock; the current 6.0.0.Final release also brings important Java, Weld, CDI, and Jupiter naming requirements.

What Weld Testing does in a JUnit test

A plain JUnit test can construct a Java class directly or supply mocks. That is useful for isolated business logic, but it does not prove that CDI can resolve the class’s injections or that container-managed behavior works. Weld Testing starts a Weld container for the test run, makes CDI available to the test class, and shuts the container down afterward. The result is a component test: the bean runs under CDI rather than as an ordinary object.

This approach is especially useful when the behavior depends on injection, interceptors, decorators, or CDI event delivery. The extension can also be combined with mocking frameworks, so a test can exercise CDI where it matters and replace unrelated collaborators where appropriate. The project provides integrations for JUnit 4, JUnit Jupiter, and Spock. The 6.0.0.Final announcement says its Jupiter extension works with JUnit 5 and 6. Weld Testing project README · Weld Testing 6.0.0.Final announcement

Weld Testing versus a plain unit test

Approach What it verifies Setup and trade-off
Direct construction or mocks Isolated class logic and the behavior of supplied collaborators; it does not establish that CDI wiring, lifecycle, interception, or event behavior works. Usually the simplest option for a focused unit test. It can miss problems that only appear when CDI manages the bean.
Weld Testing Bean behavior with CDI injection and other supported container behavior active. Requires the test extension and container setup, but avoids deploying a full application server for CDI component tests. It can still use mocks.
Full application environment Behavior that relies on services outside Weld SE’s documented feature set, such as EJB beans. Needed when the feature under test depends on enterprise services that a Weld SE test does not provide.

There are no published setup-time or execution-speed figures in the cited project sources, so this is a fidelity distinction, not a claim that one approach is measurably faster.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Compatibility requirements in Weld Testing 6.0.0.Final

The Weld project announced version 6.0.0.Final on September 29, 2026. These requirements are specific to that release; do not apply them automatically to older Weld Testing versions.

  • Java: 17 or newer.
  • Weld: 7.0.0.Final.
  • CDI: 5.0.
  • JUnit Jupiter artifact: the name changed from weld-junit5 to weld-junit-jupiter.
  • Jupiter Java package: changed from org.jboss.weld.junit5 to org.jboss.weld.junit.jupiter.
  • Custom test enrichers: migration also changes the service-provider file path for custom WeldJunitEnricher implementations.

Use the current Weld Testing README for the dependency declaration and registration details for the version you select. Older tutorials can still illustrate the extension concept, but their artifact coordinates and imports may be stale. For example, the 2017 Weld meets JUnit 5 article predates the 6.0.0.Final naming changes.

Choose the Weld line that matches your application

Weld versions are tied to CDI versions, so a testing setup should match the compatibility line used by the application rather than simply selecting the newest number. The Weld getting-started page lists these separate releases, both dated January 14, 2026:

Weld release CDI version Listed release date
5.1.7.Final 4.0 January 14, 2026
6.0.4.Final 4.1 January 14, 2026

Those are not interchangeable with the Weld 7.0.0.Final and CDI 5.0 baseline specified for Weld Testing 6.0.0.Final. Check the application’s Weld/CDI line and the matching Weld Testing documentation before changing versions. Weld Get Started

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When Weld SE is enough—and when it is not

Weld can run in Java SE, which is why a CDI test does not inherently require an application server. Weld’s reference documentation describes support for injection with qualifiers and alternatives, several scopes, interceptors, decorators, stereotypes, events, and portable extensions. It also documents an important boundary: EJB beans are not supported in Weld SE. Weld reference documentation

Quick Recap

SaleBestseller No. 3
SaleBestseller No. 4
Pragmatic Unit Testing in Java with JUnit
Pragmatic Unit Testing in Java with JUnit
Used Book in Good Condition
$14.26
SaleBestseller No. 5
Best Value
Rank #4
Sale
  • Use a Weld Testing test when the question is whether CDI-managed components work together—for example, whether an injection point resolves or an interceptor or event affects the result.
  • Use direct construction or mocks when the question is confined to a class’s own logic and container behavior is not part of the claim being tested.
  • Use a full environment when the behavior depends on EJB beans or other services not supplied by the Weld SE feature set.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.