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

后端 未结 8 1742
孤城傲影
孤城傲影 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:17

    Well they had to pick one convention. If you want to reverse it try the Hamcrest matchers. They are meant to help increase readability. Here is a basic sample:

    import org.junit.Test;
    import static org.junit.Assert.assertThat;
    import static org.hamcrest.core.Is.is;
    
    public HamcrestTest{
       @Test
       public void matcherShouldWork(){
           assertThat(   Math.pow( 2, 3 ),  is( 8 )  );
       }
    }
    

提交回复
热议问题