Test Smell: Unnecessary Test Code
The test testSearch() contains a few assertions, none expecting exceptions themselves. 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.
Unless your test expects an exception to be thrown—because you’ve explicitly designed it to set the stage for throwing an exception—you can let other exceptions fly. Don’t worry, JUnit traps any exceptions that explode out of your test. When JUnit catches an unexpected exception, it marks the test as an error, and displays the stack trace in its output.
The try/catch block surrounding all the test code adds no value. Remove it. Modify the signature of testSearch() to indicate that it can throw ...
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