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

前端 未结 7 1813
余生分开走
余生分开走 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 01:45

    The xUnit testing convention is expected/actual. So, for many that is the natural order since that's what they learnt.

    Interestingly in a break from convention for an xUnit framework qunit goes for actual/expected. At least with javascript you can just create a new function that encapsulates the old one and assign it the original variable:

    var qunitEquals = equals;
    equals = function(expected, actual, message) {
        qunitEquals(actual, expected, message);
    };
    

提交回复
热议问题