What's the difference between failure and error in JUnit?

后端 未结 8 2388
粉色の甜心
粉色の甜心 2020-11-30 06:27

I\'m running JUnit tests on a large code base, and I\'ve been realizing that sometimes I get \"Errors\" while other times I get \"Failures\". What\'s the difference?

相关标签:
8条回答
  • 2020-11-30 06:58

    Basically, failures refer to unfulfilled assertions while errors are due to abnormal test execution. and I think each IDE has symbolic icons with different colors for passed, failed, and with error tests.

    For more information, check this.

    0 讨论(0)
  • 2020-11-30 07:06

    Ironically, junit and other testing related frameworks (testng, hamcrest) provide assert operations which verify condition and if it fails then "under-the-hood" a java.lang.AssertionError is being thrown, which btw extends java.lang.Error.

    But it no way contradicts with answers above which are fully valid of course. So in order to mark specific test flow as failure one can throw AssertionError, however I'm not sure it's really documented in corresponding manuals, because more appropriate to use dedicated fail() API. Other kinds of Throwable will be considered as errors, not failures.

    0 讨论(0)
提交回复
热议问题