Why are assertEquals() parameters in the order (expected, actual)?

前端 未结 7 1815
余生分开走
余生分开走 2021-01-31 01:28

Why do so many assertEquals() or similar function take the expected value as first parameter and the actual one as second ?
This seems counter-intuitive to me,

7条回答
  •  春和景丽
    2021-01-31 01:42

    The explanation I heard is that it comes from TDD.

    In Test Driven Development, you start with the test, and then write the code.

    Starting assertions by writing the expectation, and then call the code that should produce it, is a mini version of that mindset.

    Of course, this may just be a story people tell. Don't know that it was a conscious reason.

提交回复
热议问题