Skip to content
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

Extract a ComparisonFailure interface from AssertionFailedException #27

Open
kcooney opened this issue Oct 19, 2016 · 9 comments
Open

Comments

@kcooney
Copy link

kcooney commented Oct 19, 2016

It would be useful if JUnit4's ComparisonFailure exception could share a common interface with OpenTest4J's AssertionFailedException so 1) IDEs have a simple way to show a diff view on comparison failure and 2) JUnit4 can get better IDE integration for comparison failures for things that are not strings.

This would require some changes to AssertionFailedException, since the JUnit4 ComparisonFailure class already has methods named getActual() and getExpected(). I suggest renaming OpenTest4J's AssertionFailedException methods as follows:

  • getActual() -> getActualValue()
  • getExpected() -> getExpectedValue()
  • isExpectedDefined() -> hasExpectedValue()
  • isActualDefined() -> hasActualValue()

The above four methods would be the only methods in this proposed ComparisonFailure interface

@cgruber
Copy link

cgruber commented Oct 19, 2016

I presume you didn't mean hasisActualValue() but hasActualValue()

@kcooney
Copy link
Author

kcooney commented Oct 19, 2016

@cgruber fixed. Thanks

@marcphilipp
Copy link
Member

We could certainly do this. Another option would be to change Vintage to use AssertionFailedError instead of ComparisonFailure going forward, right?

@kcooney
Copy link
Author

kcooney commented Nov 16, 2016

@marcphilipp changing JUnit4 in that way would break tests and tools

@marcphilipp
Copy link
Member

I don't think it would break a lot of tests and it would only break tools that don't support OTA, right?

@kcooney
Copy link
Author

kcooney commented Nov 16, 2016

@marcphilipp Eclipse (and probably other IDEs) special case ComparisonFailure. I have seen tests at Goggle that assume that calling certain assertion methods in certain ways result in ComparisonFailure.

While IDEs will eventually be updated to support OTA, it will take time for people to update their IDEs.

What's wrong with extracting an interface as I proposed?

@kcooney
Copy link
Author

kcooney commented Nov 27, 2016

@marcphilipp any more thoughts on this?

Note that we could change JUnit4's AssertionFailedError extend OpenTest4J's AssertionFailedException, but that would also require renaming the methods as I described in the original bug description.

@marcphilipp
Copy link
Member

How would that work in terms of artifact dependencies and JDK compatibility? JUnit4 is still compiled to JDK5 byte code while OTA4J isn't... 🤔

@kcooney
Copy link
Author

kcooney commented Nov 28, 2016

Sooner or later we will have a release of JUnit4 that is compiled with a more recent JDK (I was originally thinking that we would do that in a point-zero release, but since 5.0 is taken...). We have had a few feature requests that require JDK 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants