-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[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
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 |
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.
Hard no. I'm happy with JUnit and don't see a need to complicate matters and churn the code by using a different way to say the same things.
There is a benefit: the message when an assertion fails is much more informative than with JUnit. I often have to debug and modify the jumit message to understand what the failure is about. |
yes, its nice to have same language, easy to understand each other.
This is your issue:
And fix:
Generic assertTrue is considered outdated resulting is broad fluff. When following one framework, we should obey best practises. This will make every opinion around happy. |
JUnit has a lot more than assertTrue. There's assertEquals, assertNull, assertSame, etc. I'm OK with things JUnit doesn't have like assertContains, but I don't want to replace things JUnit already has. Guava's MoreAsserts makes a lot more sense than AssertJ. It fills the potholes, not replaces the road. |
I was wondering about what will be the next Its a clear overhead now to follow |
might use what we already got; tighten things up, instead of going crazy. When done only once right, there is not need for rival, promoting overhead. Going with
|
[POC] Migrate
JUnit
asserts toAssertJ
- impltryout: