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

@Capturing does not work as intended if used as a parameter instead of as a field (TestNG-only) #515

Closed
jotunacorn opened this issue Apr 18, 2018 · 2 comments
Assignees
Labels

Comments

@jotunacorn
Copy link

Version of JMockit that was used:

Using JMockit 1.38 and TestNG 6.14.3

Description of the problem:

When passing an @Capturing parameter the test changes behaviour from when the @Capturing is a member. The @Capturing instance does not mock the implementation of the interface when passed as a parameter. Below is a minimal class that works when the interface A is a member but not when it's a parameter.

Test.java

import mockit.Capturing;
import mockit.Expectations;

import static org.testng.Assert.assertEquals;

@org.testng.annotations.Test
public class Test {

    @Capturing A a; //Remove this line and uncomment the parameter for the test to fail.

    public void test(/*@Capturing A a*/) {
        AImpl impl = new AImpl();
        new Expectations() {{
            a.mockMethod();
            result = "test";
        }};
        assertEquals(impl.mockMethod(), "test");
    }

    private interface A {
        String mockMethod();
    }

    private class AImpl implements A {
        public String mockMethod() {
            return "Error";
        }
    }
}

Build.gradle

group 'TestNG'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile "org.testng:testng:6.14.3"
    testCompile "org.jmockit:jmockit:1.38"
}
@rliesenfeld rliesenfeld self-assigned this Apr 18, 2018
@rliesenfeld rliesenfeld changed the title @Capturing does not work as intended if used as a parameter instead of as a member @Capturing does not work as intended if used as a parameter instead of as a member (TestNG-only) Apr 20, 2018
@yasserg
Copy link

yasserg commented May 4, 2018

We spent a lot of time on updating our tests to be able to upgrade from 1.21 to latest version and now because of this bug can't upgrade. Is this going to be fixed soon and if not is there a workaround? (note that I also tried versions prior to 1.38 and each of those was failing because of other bugs (some related to interactions with TestNG) and couldn't find a recent version that was passing all tests.

@rliesenfeld rliesenfeld changed the title @Capturing does not work as intended if used as a parameter instead of as a member (TestNG-only) @Capturing does not work as intended if used as a parameter instead of as a field (TestNG-only) May 12, 2018
@rliesenfeld
Copy link
Member

Support for mock test method parameters had to be dropped, as it was no longer viable. If testng-team/testng#1164 ever gets solved, it will be added back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants