I always wondered what exactly is the meaning of actual and expected in assertEquals
in libraries like TestNG.
If we read the Java Docs we see:
public static void assertEquals(... actual, ... expected)
Parameters:
actual - the actual value
expected - the expected value
From my understanding the expected
value is the known one, so the one we expect, and the actual
one is the one we want to verify. For example, assume we want to test a function fooBar
that always has to return 56
.
In such a case I would do: assertEquals(sth.fooBar(), 56)
. But with a quick search on GitHub it seems people do it the other way around, so assertEquals(56, sth.fooBar())
. But how can the expected value be sth.fooBar()
when we don't even know that value? It seems that sth.fooBar()
is the actual value which we compare against the expected which we already know.
I know there is no difference of the correctness of a test but I would like to follow the "correct" way.