Barista icon indicating copy to clipboard operation
Barista copied to clipboard

Improve assertion error messages by adding mismatch descriptions

Open angusholder opened this issue 2 years ago • 5 comments

I added overrides for TypeSafeMatcher.describeMismatchSafely() to improve the error messages that Barista gives when the assertion fails

angusholder avatar Oct 11 '22 09:10 angusholder

Hi @angusholder

Any example on how error messages looked before this PR and how it looks with this change?

alorma avatar Nov 16 '22 10:11 alorma

Weren't there some tests for the assertion messages? I don't know what's the current status of CI

Sloy avatar Nov 16 '22 10:11 Sloy

Hi @angusholder

Any example on how error messages looked before this PR and how it looks with this change?

For assertErrorDisplayed it was previously displaying the mismatch value by calling View.toString(), like so:

Caused by: junit.framework.AssertionFailedError: 'with error: My error message 123' doesn't match the selected view. Expected: with error: My error message 123 Got: was <com.google.android.material.textfield.TextInputLayout{a8f4ca1 V.ED..... ........ 0,0-560,219 #7f0a01b8 app:id/my_view_id aid=1073741835}>

Now it displays what TextView.getError() was instead:

Caused by: junit.framework.AssertionFailedError: 'with error: "My error message 123"' doesn't match the selected view. Expected: with error: "My error message 123" Got: with error: "Some other error message 456."

angusholder avatar Nov 28 '22 16:11 angusholder

Look much better!

Is there any way, btw, to avoid this ñart?

Caused by: junit.framework.AssertionFailedError: 'with error: "My error message 123"' doesn't match the selected view.

alorma avatar Nov 28 '22 17:11 alorma

Look much better!

Is there any way, btw, to avoid this ñart?

Caused by: junit.framework.AssertionFailedError: 'with error: "My error message 123"' doesn't match the selected view.

What do you want it to say instead? I think that part is created by JUnit and Hamcrest

angusholder avatar Jan 05 '23 09:01 angusholder