Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between errors and failures in JUnit? [duplicate]

I'm learning to use JUnit.

Some of my tests have come up as "errors" and some as "failures". What's the difference between the two?

like image 741
papercuts Avatar asked Mar 05 '13 06:03

papercuts


4 Answers

An error is when something breaks and an exception occurs, such as a Null object reference.

A failure is when the test criteria is not met. i.e. when the Assert() fails.

[This is in general, not just junit.]

like image 148
Mitch Wheat Avatar answered Oct 23 '22 22:10

Mitch Wheat


In simple words,

Errors - mean that while your test was running, there were some unhandled/unforeseen exceptions, and hence, your test case basically crashed without executing fully.

Failures - mean that your test completed successfully, but the test condition of your test criteria has failed(not what you expected it to be).

like image 31
Rahul Avatar answered Oct 23 '22 23:10

Rahul


A failure is when one of your assertions fails--that is, your program does something wrong, and your JUnit test notices and reports the fact.

An error is when some other Exception occurs--one you haven't tested for and didn't expect, such as a NullPointerException or an ArrayIndexOutOfBoundsException.

like image 26
Achintya Jha Avatar answered Oct 23 '22 23:10

Achintya Jha


Failure - When test case fails (Condition that you assert did not succeed)

Error - Unexpected scenarios or errors in executing the test case

like image 40
Narendra Pathai Avatar answered Oct 24 '22 00:10

Narendra Pathai