Field comparison not ignoring synthetic members
See original GitHub issueThanks for a great library.
We are using JaCoCo for test coverage. This adds a private static field $jacocoData
to classes under test, which is marked as synthetic (see My code uses reflection. Why does it fail when I execute it with JaCoCo? in http://eclemma.org/jacoco/trunk/doc/faq.html).
Assertj then fails the test when comparing classes field by field as the $jacocoData
is different between the expected and actual. So
assertThat(eventClass).isEqualToIgnoringGivenFields(data, "types", "primaryMarkets");
then fails with the error:
java.lang.AssertionError:
Expecting value <[true, false, true, true]> in field <"$jacocoData"> but was <[true, true, true, true, true, true, true, true]> in <EventClass@2ef1972f>.
Comparison was performed on all fields but <["types", "primaryMarkets"]>
I can work round it by adding $jacocoData
to the ignored fields, but this would be fail if JaCoCo changed to use a different name or we switched to an alternative coverage tool. Ideally therefore instead assertj should ignore synthetic members as the JaCoCo FAQ suggests.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Field comparison not ignoring synthetic members #590 - GitHub
I agree, I'm just wandering if I should ignore all fields starting with $ or not (I'm assuming there is no other way...
Read more >AssertJ: `ignoringFields` is not ignoring all the provided fields?
when recursively comparing field by field, but found the following difference: field/property 'fragments' differ: - actual value : Fragments{ ...
Read more >Synthetic Fields Handling. JaCoCo. - Google Groups
Please change your code to ignore synthetic members. This is a good practice anyways as also the Java compiler creates synthetic members in ......
Read more >java.lang.reflect.Field.isSynthetic java code examples - Tabnine
Indicates whether or not this field is synthetic. Popular methods of Field. get. Returns the value of the field in the specified object....
Read more >Ignoring fields - EqualsVerifier - Jan Ouwens
Ignoring fields. By default, EqualsVerifier assumes that all (non-static) fields of your class participate in equals and hashCode .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@joel-costigliola I guess
Field.isSynthetic()
can be used?Whatever goes in 2.4 will be in 3.4, for the release you will have to wait, I’m in holidays 😃 so probably in one month.