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

后端 未结 8 2424
粉色の甜心
粉色の甜心 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 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.

提交回复
热议问题