question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Field comparison not ignoring synthetic members

See original GitHub issue

Thanks 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:closed
  • Created 8 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
PascalSchumachercommented, Jan 20, 2016

@joel-costigliola I guess Field.isSynthetic() can be used?

0reactions
joel-costigliolacommented, Feb 11, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found