Unit testing: why is the expected argument always first in equality tests?

后端 未结 8 1741
孤城傲影
孤城傲影 2020-12-15 15:34

Why is it that every unit testing framework (that I know of) requires the expected value in equality tests to always be the first argument:

Assert.AreEqual(42         


        
8条回答
  •  既然无缘
    2020-12-15 16:08

    Nobody knows and it is the source of never ending confusions. However not all frameworks follow this pattern (to a greater confusion):

    1. FEST-Assert uses normal order:

      assertThat(Util.GetAnswerToLifeTheUniverseAndEverything()).isEqualTo(42);
      
    2. Hamcrest:

      assertThat(Util.GetAnswerToLifeTheUniverseAndEverything(), equalTo(42))
      
    3. ScalaTest doesn't really make a distinction:

      Util.GetAnswerToLifeTheUniverseAndEverything() should equal (42)
      

提交回复
热议问题