Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

java - org.mockito.exceptions.misusing.unfinishedstubbingexception powerMockito

often when i use powerMockito i wrtie this sentences PowerMockito.doReturn(message).when(messageDAOMock.save(message)); i get unfinishedstubbingexception and i don't know why and hoy i can correct it. also i put

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

    @Spy
    IMessageDAO messageDAOMock = new MessageDAO();

and i am using this dependencies:

<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>

and also i use junit 4.

tihs error sometimes it happens and sometimes it doesn't but i don't find out why or how i can solve it

thanks and sorry for my english, it is not my native languaje


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can solve this problem, the error is that in the parentesis, it is not

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

else

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...