I always wondered what exactly the actual and expected assertEquals in libraries like TestNG.
If we read Java docs, we see:
public static void assertEquals(... actual, ... expected) Parameters: actual - the actual value expected - the expected value
In my opinion, the expected value is known, so we expect, and actual is the one we want to check. For example, suppose we want to test the fooBar function, which should always return 56 .
In that case, I would do: assertEquals(sth.fooBar(), 56) . But with a quick GitHub search, it seems like people are doing it the other way around, therefore assertEquals(56, sth.fooBar()) . But how can the expected value be sth.fooBar() when we don't even know this value? It seems that sth.fooBar() is the actual value that we are comparing with the expected one that we already know.
I know that there is no difference in the correctness of the test, but I would like to follow the "correct" method.
source share