Reputation: 31
When trying to run tests with mock objects, I got the following error:
org.powermock.reflect.exceptions.TooManyMethodsFoundException: Several matching methods found, please specify the argument parameter types so that PowerMock can determine which method you're referring to.
Matching methods in class android.support.v7.app.AppCompatActivity were:
void onCreate( android.os.Bundle.class )
void onCreate( android.os.Bundle.class android.os.PersistableBundle.class )
void onCreate( android.os.Bundle.class )
void onCreate( android.os.Bundle.class )
void onCreate( android.os.Bundle.class )
at nl.han.alfam.presentation.CarDetailsActivityTest.setUp(CarDetailsActivityTest.java:47)
Line 47:
suppress(method(AppCompatActivity.class, "onCreate", Bundle.class));
There are apparently multiple methods that support a Bundle.class parameter. I've tried without Bundle.class too, but that didn't help at all.
Upvotes: 3
Views: 3775
Reputation: 3530
I had similar issue with PowerMockito and Fragment
's onCreate
. This is working for me.
Instead of:
PowerMockito.suppress(PowerMockito.method(Fragment.class, "onCreate", Bundle.class));
Use:
PowerMockito.suppress(Fragment.class.getMethod("onCreate", Bundle.class));
Upvotes: 6