You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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";
}
}
}
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
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
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
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.
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 interfaceA
is a member but not when it's a parameter.Test.java
Build.gradle
The text was updated successfully, but these errors were encountered: