Using Assume.assumeTrue or Assert.assertTrue, when do tests exit?

南笙酒味 提交于 2019-12-12 01:42:10

问题


I am using JUnit 4.12 and this is my current understanding of the following APIs I use frequently:

  • assumeTrue: if expression evaluates to false, test will halt and be ignored
  • assertTrue: if condition is false, throws an AssertionError
  • assertEquals: if they are not equal, an AssertionError is thrown with the given message
  • assertNotNull: if it is null, throws an AssertionError

However, I am unable to get clarity on couple of things:

  1. my understanding is that only for assumeTrue, the tests will exit but the very definition of assert is that the program should exit when the statement evaluates to false
  2. when the test throws an AssertionError, does it exit the test case or continue executing the remaining steps?
  3. can the tests be considered pass, even if they throw an AssertionError or are the tests considered fail?

回答1:


  1. assumeTrue means that the test shouldn't run. It does not mean your code is broken and most runners will treat this test as "ignored"

  2. An AssertionError means the test has failed. No more steps in that test case (the single method) will be run. It would be pointless to do so as the test has already failed

  3. The test has failed. If you want to negate the meaning of a test there are other ways to do that, e.g. replace assertNull with assertNotNull



来源:https://stackoverflow.com/questions/36208492/using-assume-assumetrue-or-assert-asserttrue-when-do-tests-exit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!