Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TooManyActualInvocations when class is prepared for test. #656

Closed
Otanikotani opened this issue Apr 6, 2016 · 0 comments
Closed

TooManyActualInvocations when class is prepared for test. #656

Otanikotani opened this issue Apr 6, 2016 · 0 comments

Comments

@Otanikotani
Copy link

What steps will reproduce the problem?
Code:

import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockTestCase;
import org.testng.annotations.Test;

import static org.mockito.Mockito.verify;

@PrepareForTest({ SimpleTest2.SimpleFoo.class })
public class SimpleTest2 extends PowerMockTestCase {

    @Test
    public void testSetFoo() {
        SimpleTest2.SimpleFoo foo = PowerMockito.spy(new SimpleTest2.SimpleFoo());

        foo.setFoo(" ");

        verify(foo).setFoo(" ");
    }

    public static class SimpleFoo {

        private String foo;

        public void setFoo(String foo) {
            this.foo = foo;
        }
    }
}

What is the expected output?
Test passes
What do you see instead?

org.mockito.exceptions.verification.TooManyActualInvocations: 
simpleFoo.setFoo(" ");
Wanted 1 time:
-> at fr.generix.metier.bc4j.produit.SimpleTest2.testSetFoo(SimpleTest2.java:18)
But was 3 times. Undesired invocation:
-> at fr.generix.metier.bc4j.produit.SimpleTest2.testSetFoo(SimpleTest2.java:16)

    at fr.generix.metier.bc4j.produit.SimpleTest2.testSetFoo(SimpleTest2.java:18)

What version of the product are you using?
PowerMock 1.6.2
TestNG 6.9.4
On what operating system?
Win 10

Please provide any additional information below.
If

@PrepareForTest({ SimpleTest2.SimpleFoo.class })

is commented out - test passes.

if

SimpleFoo foo = Mockito.spy(new SimpleTest2.SimpleFoo());

is used instead of PowerMockito's one - test passes.

Most annoyingly, if

@PrepareForTest({ SimpleTest2.SimpleFoo.class })

is not on the current test suite class but on any other, then the test either passes or not. I guess it depends on order of tests execution. Still, it adds unpredicatability to tests results which is very annoying.

@thekingn0thing thekingn0thing added this to the PowerMock 1.6.6 milestone Apr 29, 2016
@thekingn0thing thekingn0thing self-assigned this Jun 28, 2016
thekingn0thing added a commit that referenced this issue Jul 17, 2016
* Refactoring: Move ProxyFramework into  reflection module.
* Fix #656 TooManyActualInvocations when class is prepared for test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment