stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.39k stars 1.59k forks source link

assert.Equal and similar output should be explicit about type inequality #322

Open bombela opened 8 years ago

bombela commented 8 years ago

In assert.Equal(t, a, b) if a and b do not have the same type, the test will fail, but the output will be the same as a value equality test failure.

It is confusing, because on complex equality assertion, ones might not realize the problem is different type, not unequal values.

Consider this example:

type struct Foo { V int }
type Foos []Foo
assert.Equal(t, Foos{{1}, {2}}, Foos{{1}, {2})

compared to:

assert.Equal(t, Foos{{1}, {2}}, []Foo{{1}, {2})

The second case will fail with a "not equal" message.

Instead, assert.Equal and similar should output an explicit message about type inequality.

cc @abhinav @prashantv @breerly

ernesto-jimenez commented 8 years ago

There's a PR open about improving error messages: #327

HaraldNordgren commented 6 years ago

Could likely be closed since https://github.com/stretchr/testify/pull/327 was merged.