-
Notifications
You must be signed in to change notification settings - Fork 239
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
Data provider mismatch with @Mocked annotation #337
Comments
The problem is due to the new way to manage data provider parameters: testng-team/testng#923 Maybe JMockit should upgrade its TestNG support. But let me know if a specific spi is needed to help with the integration. Ping @nitinverma who made the 6.9.11 modification, maybe he'll have a good idea for a nice integration. For reference, we have testng-team/testng#600 in the backlog too which points some integration problems on dataprovider. |
TestNG should provide an extensible mechanism for third-party libraries to provide their own custom arguments to test methods, without them having to resort to hacks as I had to do in JMockit. JUnit 5 (not JUnit 4) does provide such a mechanism (the I will see if the new parameter resolution in TestNG 6.9.11+can be supported. From the first look, it may be difficult. I don't exclude the possibility that mock parameters in test methods won't be usable anymore with these newer versions of TestNG; in that case, JMockit users would have to limit themselves to mock fields. |
testng is expecting an object that is an instance of 'DummyDomain' or null, as both are valid inputs to invoke this test method. Following snippet would satisfy testng-6.9.11 for now. @DataProvider(name = "data")
public Object[][] data() {
return new Object[][]{
new Object[]{null},
new Object[]{new DummyDomain("from-data-provider")},
};
}
@Test(dataProvider = "data", expectedExceptions = {RuntimeException.class})
public void testStore(@Mocked DummyDomain unused) {
System.out.println("unused:" + unused);
new StrictExpectations() {
{
new DummyDomain("TEST1");
try {
unused.exec();
} catch (IOException e) {
// never happen
}
result = new IOException();
}
};
dummyService.store("test");
} Happy to help n collaborate on this integration. Regards, Nitin Verma |
Refer https://github.com/jmockit/jmockit1
public static final class MockParameters extends MockUp<Parameters>
{
@Mock
public static void checkParameterTypes(
String methodName, Class<?>[] parameterTypes, String methodAnnotation, String[] parameterNames) {}
@Mock
@Nullable
public static Object getInjectedParameter(
@Nonnull Invocation invocation, Class<?> c, @Nullable Method method,
ITestContext context, ITestResult testResult)
{
((MockInvocation) invocation).prepareToProceedFromNonRecursiveMock();
Object value = Parameters.getInjectedParameter(c, method, context, testResult);
if (value != null) {
return value;
}
if (method == null) {
// Test execution didn't reach a test method yet.
return null;
}
if (method.getParameterTypes().length == 0) {
// A test method was reached, but it has no parameters.
return null;
}
if (isMethodWithParametersProvidedByTestNG(method)) {
// The test method has parameters, but they are to be provided by TestNG, not JMockit.
return null;
}
// It's a mock parameter in a test method, to be provided by JMockit.
return "";
}
} |
It stopped working for testng 6.12. Reopen?
org.testng.internal.reflect.MethodMatcherException:
|
I use JMockit 1.27
Java 1.8.92
And Windows OS
Report prints following error:
That problem happens with testng 6.9.11 and higher. With testng 6.9.10 this test runs successfully.
I am not sure the problem is in jmockit, but might be this is an issue somewhere in proxy that jmockit creates for method parameter.
Test project is here jmockit-check.zip
Thank you,
Alex
The text was updated successfully, but these errors were encountered: