logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

Migrate `log4j-core-test` to JUnit 5

Open ninetteadhikari opened this issue 1 year ago • 11 comments

Introduction

We are from Neighbourhoodie, the implementation partner of the STF Bug Resilience Program. This work is part of our agreed Milestone 1. Upgrade from JUnit 4 to JUnit 5. This PR migrates the tests located in log4j-core-test to JUnit5.c

Please note the log4j-core-test module contains over 150 files and this PR updates the tests for 40 of them. Further PRs will be made to update the rest of the tests.

Checklist

  • [x] Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • [x] ./mvnw verify succeeds (if it fails due to code formatting issues reported by Spotless, simply run ./mvnw spotless:apply and retry)
  • [ ] Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • [ ] Tests for the changes are provided
  • [x] Commits are signed (optional, but highly recommended)

ninetteadhikari avatar Oct 07 '24 09:10 ninetteadhikari

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED

Generated by gradle/develocity-actions

github-actions[bot] avatar Oct 07 '24 10:10 github-actions[bot]

Please note the log4j-core-test module contains over 150 files and this PR updates the tests for 40 of them. Further PRs will be made to update the rest of the tests.

@ninetteadhikari, @hulkoba, thanks so much! :heart_eyes: Would it be possible to keep all JUnit 4-to-5 migration changes in this PR for log4j-core-test instead of creating more follow-up PRs?

vy avatar Oct 07 '24 10:10 vy

Please note the log4j-core-test module contains over 150 files and this PR updates the tests for 40 of them. Further PRs will be made to update the rest of the tests.

@ninetteadhikari, @hulkoba, thanks so much! 😍 Would it be possible to keep all JUnit 4-to-5 migration changes in this PR for log4j-core-test instead of creating more follow-up PRs?

sure thing:) let me then convert this PR to draft and open it for review later once we have migrated all the files.

ninetteadhikari avatar Oct 10 '24 08:10 ninetteadhikari

hi @vy we had a quick question, we are trying to write new extensions to replace some of the old ones and getting some errors. For example we created JndiExtension to replace the JndiRule however the build fails with this error:

Failed to execute goal biz.aQute.bnd:bnd-baseline-maven-plugin:7.0.0:baseline (check-api-compat) on project log4j-core-test: An error occurred while calculating the baseline: Baseline problems detected. See the report in /home/runner/work/logging-log4j2/logging-log4j2/log4j-core-test/target/baseline/log4j-core-test-2.25.0-SNAPSHOT.txt.

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal biz.aQute.bnd:bnd-baseline-maven-plugin:7.0.0:baseline (check-api-compat) on project log4j-core-test: An error occurred while calculating the baseline

do we have to add anything additional to make extensions work or make changes to the build? let us know thanks!

ninetteadhikari avatar Nov 14 '24 11:11 ninetteadhikari

@ninetteadhikari, that is an API compatibility check failure – see Fixing API compatibility check failures .

vy avatar Nov 14 '24 12:11 vy

we created JndiExtension to replace the JndiRule however the build fails with this error:

@ninetteadhikari, this is a breaking change to log4j-core-test. Though we are not that strict about backward compatibility when it comes to utility classes in *-test modules. You'll probably need a @BaselineIgnore("2.24.1") in package-info.java of the associated package.

vy avatar Nov 14 '24 13:11 vy

thanks so much for the response! we'll see if we can make it work:)

ninetteadhikari avatar Nov 14 '24 15:11 ninetteadhikari

Hi @vy sorry to bug you again, we tried ignoring different versions but had no luck: @BaselineIgnore("2.24.0"), @BaselineIgnore("2.24.1"), @BaselineIgnore("2.25.0")

We are still getting the same build failure. To give you a bit of a context I pushed the extension change commit here and these are the build failures we are seeing. Please let us know if you have insights into this thanks!

ninetteadhikari avatar Nov 15 '24 13:11 ninetteadhikari

@ninetteadhikari, I think your changes need to be sync'ed with 2.x. Could you try the following, please?

  1. get fetch -p upstream (Assuming upstream points to the official apache/logging-log4j2 repository)
  2. git rebase upstream/2.x
  3. Edit log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/package-info.java, set the version to 2.25.0, commit your changes
  4. Validate the fix: ./mvnw verify -DskipTests -pl :log4j-core-test
  5. git push -f

(I was able to fix the issue locally, but since you did not give us rights to edit your PRs, I could not push them.)

vy avatar Nov 15 '24 19:11 vy

This PR is now ready for review, thank you! 🙏

Please note that, even though LoggerSerializationTest is part of log4j-core-test, it was refactored in this other PR https://github.com/apache/logging-log4j2/pull/3218

AlbaHerrerias avatar Dec 13 '24 10:12 AlbaHerrerias

I'll move this to after release 2.25.0, unless someone has time to review it.

ppkarwasz avatar May 13 '25 17:05 ppkarwasz