如何解决不必要的存根异常
我的代码如下,
@RunWith(MockitoJUnitRunner.class)
public class MyClass {
private static final String code ="Test";
@Mock
private MyClassDAO dao;
@InjectMocks
private MyClassService Service = new MyClassServiceImpl();
@Test
public void testDoSearch() throws Exception {
final String METHOD_NAME = logger.getName().concat(".testDoSearchEcRcfInspections()");
CriteriaDTO dto = new CriteriaDTO();
dto.setCode(code);
inspectionService.searchEcRcfInspections(dto);
List<SearchCriteriaDTO> summaryList = new ArrayList<SearchCriteriaDTO>();
inspectionsSummaryList.add(dto);
when(dao.doSearch(dto)).thenReturn(inspectionsSummaryList);//got error in this line
verify(dao).doSearchInspections(dto);
}
}
我得到以下例外
org.mockito.exceptions.misusing.UnnecessaryStubbingException: Unnecessary stubbings detected in test class: Test Clean & maintainable test code requires zero unnecessary code. Following stubbings are unnecessary (click to navigate to relevant line of code): 1. -> at service.Test.testDoSearch(Test.java:72) Please remove unnecessary stubbings or use 'silent' option. More info: javadoc for UnnecessaryStubbingException class. at org.mockito.internal.exceptions.Reporter.formatUnncessaryStubbingException(Reporter.java:838) at org.mockito.internal.junit.UnnecessaryStubbingsReporter.validateUnusedStubs(UnnecessaryStubbingsReporter.java:34) at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:49) at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:103) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
请帮我解决如何