2

I'm learning JUnit 4. I came across annotation @Test(Timeout=). when I run this test case and if execution takes more than specified milliseconds, if shows as Error. I guess it should be under failure! if someone could explain me why this is an error not failure. Thanks

Screenshot of JUnit in Eclipse Luna

Ajeetkumar
  • 1,271
  • 7
  • 16
  • 34
  • Extremely related: [What's the difference between failure and error in JUnit?](http://stackoverflow.com/questions/3425995/whats-the-difference-between-failure-and-error-in-junit). – Duncan Jones Feb 10 '15 at 13:59

1 Answers1

2

Failures are for when you make an assertion and it turns out to be false. It means that your code did not produce the correct result to satisfy your test. Or your test code is wrong.

Errors are for when something unexpected has happened and prevented your test completing normally. Timeouts fit nicely into this category - they are a safety net to ensure your build will always complete, even if your tests run away with themselves. By using a timeout, you are not making an assertion about runtime, you are merely defending against infinite builds.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254