Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build-weld-junit:
name: "Weld Testing build, JDK ${{matrix.java.name}}"
name: "Weld Testing build, JDK ${{matrix.java.name}}, JUnit ${{matrix.junit.name}}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -20,6 +20,15 @@ jobs:
name: "21",
java-version: 21,
}
junit:
- {
name: "5.x",
profile: "junit5",
}
- {
name: "6.x",
profile: "junit6",
}
steps:
- uses: actions/checkout@v5
- name: Set up JDK @{}
Expand All @@ -40,8 +49,8 @@ jobs:
# Caching is an automated pre/post action that installs the cache if the key exists and exports the cache
# after the job is done. In this case we refresh the cache monthly (by changing key) to avoid unlimited growth.
key: q2maven-master-${{ steps.get-date.outputs.date }}
- name: Build with Maven
run: WELD_JUNIT_DEBUG=spotbugs mvn clean install -Dno-format -Dspotbugs.failOnError=true
- name: Build with Maven (JUnit ${{matrix.junit.name}})
run: WELD_JUNIT_DEBUG=spotbugs mvn clean install -P${{matrix.junit.profile}} -Dno-format -Dspotbugs.failOnError=true
- name: Delete Local Artifacts From Cache
shell: bash
run: rm -r ~/.m2/repository/org/jboss/weld/weld-junit*
Expand All @@ -53,5 +62,5 @@ jobs:
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-reports-jdk${{matrix.java.name}}
name: test-reports-jdk${{matrix.java.name}}-junit${{matrix.junit.name}}
path: 'test-reports.tgz'
113 changes: 113 additions & 0 deletions JUNIT_VERSION_COMPATIBILITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# JUnit Version Compatibility

## Overview

The `weld-junit-jupiter` module **supports both JUnit Jupiter 5.x and 6.x** through a `provided` scope dependency strategy.

## How It Works

### Dependency Scope Strategy

JUnit dependencies in `weld-junit-jupiter` are declared with `provided` scope:

```xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>provided</scope>
</dependency>
```

This means:
- **weld-junit-jupiter does NOT bundle JUnit** - users must provide their own JUnit version
- Users can choose to use **JUnit Jupiter 5.x OR 6.x** based on their project needs
- No version conflicts with user's own JUnit dependency

### Supported Versions

- ✅ **JUnit Jupiter 5.0+** through **6.x**
- ✅ **JUnit Platform 5.0+** through **6.x**

### User Configuration

Users simply add `weld-junit-jupiter` and their preferred JUnit version:

```xml
<!-- Add weld-junit-jupiter -->
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit-jupiter</artifactId>
<version>6.0.0</version>
<scope>test</scope>
</dependency>

<!-- Choose your JUnit version (5.x or 6.x) -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>6.0.0</version> <!-- or 5.13.4, or any 5.x/6.x version -->
<scope>test</scope>
</dependency>
```

## Testing Strategy

The weld-testing project is tested against **both JUnit 5.x and 6.x**:
- **JUnit 6.0.0** (primary/default): 140/140 tests passing ✅
- **JUnit 5.13.4** (backward compatibility): 140/140 tests passing ✅

### Running Tests with Different JUnit Versions

To test with JUnit 5.x:
```bash
mvn test -Pjunit5
```

To test with JUnit 6.x (default):
```bash
mvn test -Pjunit6
# or simply:
mvn test
```

### Maven Profiles

The project includes two Maven profiles for dual version testing:

- **`junit6`** (active by default): Tests with JUnit Jupiter 6.0.0 and JUnit Platform 6.0.0
- **`junit5`**: Tests with JUnit Jupiter 5.13.4 and JUnit Platform 1.12.2

## Migration from JUnit 5 to JUnit 6

Users can migrate from JUnit 5 to JUnit 6 independently of upgrading weld-testing:

1. Upgrade to weld-testing 6.0.0 while staying on JUnit 5.x
2. Later, upgrade to JUnit 6.x when ready

OR

1. Upgrade to JUnit 6.x first
2. Then upgrade to weld-testing 6.0.0

Both paths are supported!

## API Compatibility

The weld-junit-jupiter module:
- Uses only stable JUnit APIs available in both 5.x and 6.x
- Avoids deprecated APIs that were removed in JUnit 6
- Has been updated for JUnit 6 API changes:
- `MethodOrderer.Alphanumeric` → `MethodOrderer.MethodName`
- `CollectionUtils.toUnmodifiableList()` → `Stream.toList()`

## Version Support Policy

- **Minimum supported version**: JUnit Jupiter 5.0.0
- **Maximum supported version**: JUnit Jupiter 6.x (latest)
- **Java baseline**: Java 17+ (required by JUnit 6)

## Known Limitations

- The Spock module currently has compatibility issues with JUnit Platform 6.0.0 due to upstream changes
- This is a known issue being tracked in the Spock project
- Spock users should continue using JUnit Platform 5.x until Spock 2.5+ is released
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Weld Testing Extensions

[![Maven Central](http://img.shields.io/maven-central/v/org.jboss.weld/weld-junit4.svg)](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22weld-junit4%22)
[![Maven Central](http://img.shields.io/maven-central/v/org.jboss.weld/weld-junit-jupiter.svg)](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22weld-junit-jupiter%22)
[![License](https://img.shields.io/badge/license-Apache%20License%202.0-yellow.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)

The primary goal of this project is to provide simple and fast tools for CDI *unit/component* testing.
The tools are implemented as JUnit 4, JUnit 5 and Spock extensions.
The tools are implemented as JUnit Jupiter and Spock extensions.

:warning: **Version 5.x of this extension supports Weld 6.0 (CDI 4.1) along with `jakarta` namespace**
:warning: **Version 6.x of this extension supports Weld 6.0 (CDI 4.1) with `jakarta` namespace, JUnit Jupiter 5.x and 6.x, and requires Java 17+**

## The What

Expand All @@ -24,18 +24,16 @@ Simulating field injection to start with, then interceptors and/or decorators -
There are frameworks to make this easier such as [Mockito](http://site.mockito.org/); but use too many mocks and things get tangled real quick.
So we came with JUnit/Spock extensions which allow you to use actual CDI container instead of complex simulations.
There is no need to change the way you develop your CDI components if you have a real container to test it with.
Besides, it's easy to combine this approach with mocking frameworks (see for instance [Adding mock beans](junit5/README.md#adding-mock-beans)).
Besides, it's easy to combine this approach with mocking frameworks (see for instance [Adding mock beans](junit-jupiter/README.md#adding-mock-beans)).

## How To Use Each Extension

This project consists of three modules.
Below is a list with links to detailed README of each extension:

* JUnit 4 extension
* [JUnit 4 extension using `@Rule` and `@ClassRule` mechanism](junit4/README.md)
* JUnit 5
* [JUnit 5 extension using the `@ExtendWith` mechanism](junit5/README.md)
* JUnit-common
* Houses the parts of code shared by both Junit extensions
* JUnit Jupiter (JUnit 5 & 6)
* [JUnit Jupiter extension using the `@ExtendWith` mechanism](junit-jupiter/README.md)
* Weld Common
* Houses the shared testing utilities used by both JUnit Jupiter and Spock extensions
* Spock
* [Spock framework extension](spock/README.md)
File renamed without changes.
Loading