Test Smell: Unnecessary Test Code
The test code that comprises testSearch() doesn’t expect any exceptions to be thrown. It contains a number of assertions against positive facts. If the test code throws an exception, a try/catch block catches it, spews a stack trace onto System.out, and explicitly fails the test. In other words, exceptions are unexpected by this test method.
Unless your tests expect an exception to be thrown—because you’ve explicitly designed the test to set the stage for throwing an exception—you can simply let the exceptions fly. Don’t worry, JUnit traps any exceptions that explode out of your test. JUnit marks a test that throws an exception as an error and displays the stack trace in its output. The explicit try/catch block ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access