rubytestingminitest

Why should I use assert_equal instead of just assert with an equal operator in minitest?


I really enjoy Minitest and it's simplicity but I don't understand why I should use assert_equal instead of assert with the == operator.

If I look into the Implementation the assert_equal method does exactly the same as I said with the equal operator.

Why do I need this step in between and not just use it directly?

I also think that it won't be more readable just because of the equal there since == is pretty self explaining.


Solution

  • Usually you want assert_equal when you prefer clear failure messages.

    When you write assert a == b and the test fails for any reason, the message would just say something along the lines of Assertion failed. On the other hand, if you use assert_equal a, b a failure will show a message like Expected a to be equal to b which gives you a bit more detail about why the test failed.