Migrate TestNG SoftAssert to AssertJ SoftAssertions#1063
Merged
timtebeek merged 1 commit intoJul 24, 2026
Merged
Conversation
juherr
force-pushed
the
juherr/migrate-testng-softassert-to-assertj
branch
2 times, most recently
from
July 23, 2026 20:38
fa7c970 to
034ac4a
Compare
Add the `TestNgSoftAssertToAssertJ` recipe and wire it into the `TestNgToAssertj` declarative recipe so that TestNG soft assertions (`org.testng.asserts.SoftAssert`) are converted to AssertJ soft assertions (`org.assertj.core.api.SoftAssertions`). The recipe rewrites the instance assertion calls (`softAssert.assertEquals(actual, expected)` -> `softAssert.assertThat(actual).isEqualTo(expected)`) while preserving the receiver, then a `ChangeType` step handles the variable type, the constructor, imports, and the identically named `assertAll()`/`fail(...)` methods. The assertion methods are declared on `org.testng.asserts.Assertion` (SoftAssert only adds `assertAll`), so the matcher targets that type and a receiver-type guard keeps direct `Assertion` (hard) usage untouched. Covered methods: assertEquals/assertNotEquals (actual/expected order, message, and floating-point delta overloads), assertTrue/assertFalse, assertNull/assertNotNull, assertSame/assertNotSame, and assertEqualsNoOrder (-> containsExactlyInAnyOrder). Also broaden the assertj-core `onlyIfUsing` dependency trigger from `org.testng.*` to `org.testng..*` so classes using only `org.testng.asserts.SoftAssert` still get the dependency added.
juherr
force-pushed
the
juherr/migrate-testng-softassert-to-assertj
branch
from
July 23, 2026 20:57
034ac4a to
d942deb
Compare
timtebeek
self-requested a review
July 23, 2026 22:36
timtebeek
approved these changes
Jul 24, 2026
timtebeek
left a comment
Member
There was a problem hiding this comment.
Perfect, thanks a lot! Good to see this soft assert gap closed as well. We'll likely do a .patch release later today, or the regular release mid next week.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed
Adds a
TestNgSoftAssertToAssertJrecipe, wired into the existingTestNgToAssertjdeclarative recipe, to migrate TestNG soft assertions (org.testng.asserts.SoftAssert) to AssertJ soft assertions (org.assertj.core.api.SoftAssertions).How it works
The instance assertion calls are rewritten first, keeping the receiver, then a
ChangeTypestep handles the variable type, the constructor, imports, and the identically namedassertAll()/fail(...)methods.The assertion methods (
assertEquals,assertTrue, ...) are declared onorg.testng.asserts.Assertion—SoftAssertonly addsassertAll— so the matcher targetsAssertionand a receiver-type guard keeps directAssertion(hard) usage untouched.Covered methods
assertEquals/assertNotEquals— preserving TestNG's(actual, expected)order, plus the message and floating-point delta overloads (isCloseTo(..., within(...))/isNotCloseTo(...))assertTrue/assertFalseassertNull/assertNotNullassertSame/assertNotSameassertEqualsNoOrder→containsExactlyInAnyOrderassertAll()andfail(...)keep the same name and are handled byChangeTypeNotes
assertj-coreonlyIfUsingdependency trigger fromorg.testng.*toorg.testng..*, so classes using onlyorg.testng.asserts.SoftAssertstill get the dependency added.SoftAssertions.assertSoftly(s -> { ... })is intentionally not emitted; the explicit instance +assertAll()shape is a 1:1 mapping.Tests added to
TestNgToAssertJTestcover the full flow, every overload branch, non-variable receivers (inlinenew SoftAssert()and fields), theassertEqualsNoOrdermapping,fail(...)passthrough, boxed-Doubledeltas, and a negative test asserting directAssertionusage is left unchanged.