assert vs. JUnit Assertions

前端 未结 6 957
难免孤独
难免孤独 2020-11-29 03:32

Today I saw a JUnit test case with a java assertion instead of the JUnit assertions—Are there significant advantages or disadvantages to prefer one over the other?

6条回答
  •  渐次进展
    2020-11-29 03:39

    When a test fails you get more infomation.

    assertEquals(1, 2); results in java.lang.AssertionError: expected:<1> but was:<2>

    vs

    assert(1 == 2); results in java.lang.AssertionError

    you can get even more info if you add the message argument to assertEquals

提交回复
热议问题