Sjo*_*erd 2 java android unit-testing mocking
尝试使用模拟对象运行测试时,出现以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
第 47 行:
suppress(method(AppCompatActivity.class, "onCreate", Bundle.class));
Run Code Online (Sandbox Code Playgroud)
显然有多种方法支持 Bundle.class 参数。我也试过不使用 Bundle.class,但这根本没有帮助。
我曾与PowerMockito和类似的问题Fragment的onCreate。这对我有用。
代替:
PowerMockito.suppress(PowerMockito.method(Fragment.class, "onCreate", Bundle.class));
Run Code Online (Sandbox Code Playgroud)
用:
PowerMockito.suppress(Fragment.class.getMethod("onCreate", Bundle.class));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2690 次 |
| 最近记录: |