Why doesn't JUnit provide assertNotEquals methods?

后端 未结 11 1105
忘了有多久
忘了有多久 2020-12-12 08:30

Does anybody know why JUnit 4 provides assertEquals(foo,bar) but not assertNotEqual(foo,bar) methods?

It provides assertNotSame

11条回答
  •  抹茶落季
    2020-12-12 09:18

    The obvious reason that people wanted assertNotEquals() was to compare builtins without having to convert them to full blown objects first:

    Verbose example:

    ....
    assertThat(1, not(equalTo(Integer.valueOf(winningBidderId))));
    ....
    

    vs.

    assertNotEqual(1, winningBidderId);
    

    Sadly since Eclipse doesn't include JUnit 4.11 by default you must be verbose.

    Caveat I don't think the '1' needs to be wrapped in an Integer.valueOf() but since I'm newly returned from .NET don't count on my correctness.

提交回复
热议问题