-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[POC] Migrate JUnit
asserts to AssertJ
- impl
#2307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
JUnit
asserts to AssertJ
bug:
|
JUnit
asserts to AssertJ
JUnit
asserts to AssertJ
- POC
JUnit
asserts to AssertJ
- POC
JUnit
asserts to AssertJ
- POC: impl/
bug: missing dependency check:
|
kindly request some feedback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR contains unrelated commis.
yes will squash. This anyway just demo.
Need to pitch and sync with community. Might be obvious that we benefit from strict diet, but of course all need to be heard, as |
Illustration of New Code Already Being Out of Sync (Considered Outdated)
JUnit vs AssertJ ComparisonIn summary:
Personal ExperienceIn my last project using JUnit5, we still maintained a StackOverflow reference about the Proposal: Standardizing Test StyleKey points:
Current problems:
Goal:
|
JUnit
asserts to AssertJ
- POC: impl/
JUnit
asserts to AssertJ
- impl
e3d5e17
to
432c7a3
Compare
assertNotNull(v); | ||
assertEquals("", v.toString()); | ||
assertThat(v).isNotNull(); | ||
assertThat(v.toString()).isEqualTo(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any isEmpty()
assertion ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any
isEmpty()
assertion ?
If not, you can create custom assertions for AssertJ very easly. I do this quite a lot at work for custom objects/classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be a bug, as failed to choose: https://docs.openrewrite.org/recipes/java/testing/assertj/simplifyassertjassertion
Or simply need to chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any change not standardized is weakened.
Simplest way would be JUnit Jupiter best practices
and allow both.
or (continuous) migrate JUnit
asserts to AssertJ
like seen here.
Both will cure generic assertTrue
statements elevate into assertThat
.
Which lib
is actually an random impl. detail.
assertNotEquals(v2, v1, "expected " + v2 + " != " + v1); | ||
assertThat(Integer.signum(v1.compareTo(v2))).as("expected " + v1 + " > " + v2).isEqualTo(1); | ||
assertThat(Integer.signum(v2.compareTo(v1))).as("expected " + v2 + " < " + v1).isEqualTo(-1); | ||
assertThat(v2).as("expected " + v1 + " != " + v2).isNotEqualTo(v1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't those messages automatically generated by assertJ in case of failures ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's still room for improvements.
It would be nice if the details of the commit include a command used to refactor.
you mean this? https://docs.openrewrite.org/recipes/java/testing/assertj/junittoassertj#usage
|
I would argue against this change now, realising and remembering that JUnit 5 looks almost 1o1 the same like AssertJ. Both following and featuring We could apply the API changes avoiding generic fluff |
[POC] Migrate
JUnit
asserts toAssertJ
- impltryout: