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

@Injectable and @Mocked test parameters not working in 1.33+ #468

Closed
jotunacorn opened this issue Oct 11, 2017 · 1 comment
Closed

@Injectable and @Mocked test parameters not working in 1.33+ #468

jotunacorn opened this issue Oct 11, 2017 · 1 comment

Comments

@jotunacorn
Copy link

jotunacorn commented Oct 11, 2017

I currently have a testsuite which has previously been running on TestNG 6.9.10 and JMockit 1.30. When updating it to TestNG 6.11 and JMockit 1.35 I run into errors on all my @Mocked and @Interface annotations in parameters for my tests. The error is that my expectations no longer mock the results of the methods in the mocked instance.

As I understood the documentation having @Mocked or @Injectable in a test parameter would mean they work the same as if they were a member with the annotation, but only accessable inside the scope of the test.

A minimal class replicating this problem is seen below. The intension is that both tests should work the same way, but in newer versions of JMockit the @Injectable pSet returns 0 as size instead of 10. Is this a user error by me, or is it a bug introduced in newer versions of JMockit?

import java.util.Set;

import mockit.Expectations;
import mockit.Injectable;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;


@Test
public class MinimalJMockitExample {

    @Injectable Set<String> mSet;

    @Test
    public void test1(){
        new Expectations() {{
            mSet.size();
            result = 10;
        }};
        assertEquals(mSet.size(), 10);
    }

    @Test
    public void test2(@Injectable Set<String> pSet){
        new Expectations() {{
            pSet.size();
            result = 10;
        }};
        assertEquals(pSet.size(), 10);
    }
}
@rliesenfeld
Copy link
Member

Fixed by #464.

@jmockit jmockit locked and limited conversation to collaborators Oct 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants