java.lang.AssertionError: expected:<2> but was:<4>

Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

Expert tip

Check your pattern declaration or check your assert declaration.


My guess is there is some kind of static state in the code being tested or in the test itself, so the tests aren't isolated. Adding the test changes the test order. In any case, your best course of action is to use the debugger to see why the tests fail.

Solutions on the web

via Coderanch by amir Ghannad, 1 year ago
expected:<2> but was:<0> at java.lang.AssertionError: expected:<2> but was:<0>
via GitHub by anuraaga
, 8 months ago
expected:<3> but was:<2>
via GitHub by hasancelik
, 2 years ago
expected:<500> but was:<4156>
via Google Groups by Erik Ramfelt, 3 months ago
java.lang.AssertionError: expected:<2> but was:<4>
at org.junit.Assert.failNotEquals(
at org.junit.Assert.assertEquals(
at org.junit.Assert.assertEquals(
at com.hazelcast.client.heartbeat.ClientHeartbeatTest$
at com.hazelcast.test.HazelcastTestSupport.assertTrueAllTheTime(
at com.hazelcast.client.heartbeat.ClientHeartbeatTest.testClientEndpointsDelaySeconds_whenHeartbeatResumed(

Users with the same issue

Once, 3 days ago
8 times, 1 week ago
Once, 1 week ago
53 times, 1 week ago
Once, 2 weeks ago

Write tip

Know the solutions? Share your knowledge to help other developers to debug faster.