>这里是代码
public class TodoBusinessImpl {
BusinessManager businessManager;
public TodoBusinessImpl(BusinessManager businessManager) {
this.businessManager = businessManager;
}
public List<String> retrieveTodosRelatedToSpring(String user) {
List<String> filteredTodos = new ArrayList<String>();
Map<String, String> test = businessManager.getDetails();
return filteredTodos;
}
}
这有什么问题?我做错了什么
public class MockitoTest {
private BusinessManager businessManager;
@Before
public void setUp() {
businessManager = Mockito.mock(BusinessManager.class);
}
@Test
public void retrieveTodosRelatedToSpringTest() {
TodoBusinessImpl todoBusinessImpl = new TodoBusinessImpl(businessManager);
Mockito.when(todoBusinessImpl.retrieveTodosRelatedToSpring("test"))
.thenReturn(Arrays.asList("test"));
}
}
这是测试类。 获取异常 org.mockito.exceptions.misusing.WrongTypeOfReturnValue: ArrayList 不能由 getDetails(( 返回
你必须调用你正在测试的方法,而不是嘲笑它的行为"不要告诉它被调用时该怎么做"。 而不是:
Mockito.when(todoBusinessImpl.retrieveTodosRelatedToSpring("test")).thenReturn(Arrays.asList("test"));
您应该这样做:
List<String> list = todoBusinessImpl.retrieveTodosRelatedToSpring("test");
// print list or assert it's content to make sure you're getting the right response