我在运行测试时遇到异常.我正在使用Mockito进行嘲弄.Mockito图书馆提到的提示没有帮助.
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at com.a.b.DomainTestFactory.myTest(DomainTestFactory.java:355)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, you naughty developer!
at a.b.DomainTestFactory.myTest(DomainTestFactory.java:276)
..........
Run Code Online (Sandbox Code Playgroud)
来自DomainTestFactory的测试代码.当我运行以下测试时,我看到了异常
@Test
public myTest(){
MyMainModel mainModel = Mockito.mock(MyMainModel.class);
Mockito.when(mainModel.getList()).thenReturn(getSomeList()); --> Line 355
}
private List<SomeModel> getSomeList() {
SomeModel model = Mockito.mock(SomeModel.class);
Mockito.when(model.getName()).thenReturn("SomeName"); --> Line 276
Mockito.when(model.getAddress()).thenReturn("Address");
return Arrays.asList(model);
}
public class SomeModel extends SomeInputModel{
protected String address;
protected List<SomeClass> properties; …Run Code Online (Sandbox Code Playgroud) 我Unfinished Stubbing detected here在运行以下代码时收到错误消息:
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.*;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
@RunWith(PowerMockRunner.class)
public class PatchWriterTaskTest {
@Before
public void before() throws Exception {
filePath = getFilePath();
task = PowerMockito.spy(new PatchWriterTask());
patchFilesName = new HashMap<Integer, String>();
patchFilesName.put(1, "TCE_RDF_COVERED_DATA_REGION.sql");
scriptPath = new File(filePath + "do_patch_rdf.sql");
PowerMockito.when(task, "getLogger").thenReturn(logger);
PowerMockito.when(task, "getPatchFilesName").thenReturn(patchFilesName);
PowerMockito.when(task, "getDirectoryPath").thenReturn(filePath);
PowerMockito.when(task, "saveDoPatchFile");
}
@Test
public void testUpdateIssuesTable() throws Exception {
PatchWriterTask task = new PatchWriterTask();
Connection conn = mock(Connection.class);
PreparedStatement …Run Code Online (Sandbox Code Playgroud)