Why doesn't JUnit provide assertNotEquals methods?

后端 未结 11 1129
忘了有多久
忘了有多久 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:06

    Modulo API consistency, why JUnit didn't provide assertNotEquals() is the same reason why JUnit never provided methods like

    • assertStringMatchesTheRegex(regex, str) vs. assertStringDoesntMatchTheRegex(regex, str)
    • assertStringBeginsWith(prefix, str) vs. assertStringDoesntBeginWith(prefix, str)

    i.e. there's no end to providing a specific assertion methods for the kinds of things you might want in your assertion logic!

    Far better to provide composable test primitives like equalTo(...), is(...), not(...), regex(...) and let the programmer piece those together instead for more readability and sanity.

提交回复
热议问题