org.mockito.exceptions.misusing.unfinishedstubingexception powermockito

hjqgdpho  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(433)

当我使用powermockito时,我经常会写这样的句子 PowerMockito.doReturn(message).when(messageDAOMock.save(message)); 我得到未完成的存根异常,我不知道为什么,我可以纠正它。我还把

@RunWith(PowerMockRunner.class)
@PrepareForTest(MessageService.class)
public class MessageServiceTest{
    @Spy
    MessageService serviceToTest = new MessageService();

    @Spy
    IMessageDAO messageDAOMock = new MessageDAO();

我用的是:

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 -->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>2.0.9</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 -->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito2</artifactId>
            <version>2.0.9</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/cglib/cglib -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.3.0</version>
        </dependency>

我也使用JUnit4。
错误有时会发生,有时不会,但我不知道为什么或如何解决它
谢谢,对不起,我的英语不是我的母语

deyfvvtc

deyfvvtc1#

我可以解决这个问题,错误是在亲子关系中,它不是

PowerMockito.doReturn(message).when(messageDAOMock.save(message));

其他的

PowerMockito.doReturn(message).when(messageDAOMock).save(message);

相关问题