nicer debugging output with jUnit's ComparisonFailure

View: New views
2 Messages — Rating Filter:   Alert me  

nicer debugging output with jUnit's ComparisonFailure

by szczepik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ComparisonFailure has some extra benefits in modern IDEs, e.g. eclipse offers extra pop-up info with detailed comparison highlighting the differences.

I propose to use this exception for assertEquals() on other types as well. It could work like this:

1. assertEquals(foo, foo2);
2. if the assertion fails
2.1 if the foo.toString() is not equal to foo2.toString() then throw new ComparisonFailure(foo.toString(), foo2.toString())
2.2 if the foo.toString() is equal to foo2.toString() then DON'T throw ComparisonFailure because it is confusing
3. assertion doesn't fail. Good for you.

This is a proposal - not sure what are the drawbacks. I think this feature is useful because on the occasion I remember I temporarily refactored assertions into assertEquals(expected.toString(), actual.toString()) just to have nicer message


Re: nicer debugging output with jUnit's ComparisonFailure

by David Saff :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I can dig it.  Can you add a feature request on github?

   David Saff

On Mon, Oct 12, 2009 at 4:15 PM, szczepik <szczepik@...> wrote:

> ComparisonFailure has some extra benefits in modern IDEs, e.g. eclipse offers extra pop-up info with detailed comparison highlighting the differences.
>
> I propose to use this exception for assertEquals() on other types as well. It could work like this:
>
> 1. assertEquals(foo, foo2);
> 2. if the assertion fails
> 2.1 if the foo.toString() is not equal to foo2.toString() then throw new ComparisonFailure(foo.toString(), foo2.toString())
> 2.2 if the foo.toString() is equal to foo2.toString() then DON'T throw ComparisonFailure because it is confusing
> 3. assertion doesn't fail. Good for you.
>
> This is a proposal - not sure what are the drawbacks. I think this feature is useful because on the occasion I remember I temporarily refactored assertions into assertEquals(expected.toString(), actual.toString()) just to have nicer message
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>