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

AssertionError message is unhelpful when match fails for byte type #254

Closed
jamesmudd opened this issue Apr 17, 2019 · 0 comments
Closed

Comments

@jamesmudd
Copy link
Contributor

Here is an example of a JUnit 5 test displaying this issue:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

public class ExampleTest {

	@Test
	void testByte() {
		assertThat((byte) 5, is(equalTo(5))); // Error message is bad
	}

	@Test
	void testShort() {
		assertThat((short) 5, is(equalTo(5))); // Error message is good
	}
}

From testShort the error message is good: (Note: <5s>)

Expected: is <5>
     but: was <5s>

But from testByte you get:

Expected: is <5>
     but: was <5>

Which looks ok <5> is <5>! Of course the reason the failed is the types are mismatched so the failure is correct, but it would be good to show this more clearly in the message.

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

1 participant