Test Smell: Unnecessary Test Code
Explore how to refine your JUnit tests by identifying and removing unnecessary test code. Learn to handle exceptions properly without clutter, and eliminate redundant assertions like not-null checks to improve test clarity and maintainability.
We'll cover the following...
We'll cover the following...
Expect the exceptions
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. ...