我已经在测试包中编写了这个测试,用于测试一个retrofit类,但是即使在测试星之前,除了未知的“常量”之外@Config,还会显示此错误:
@Config(constants = BuildConfig.class, sdk =21, manifest="app/manifests/AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class MultiFactorAPITest {
private MainActivity mainActivity;
@Mock
private MultiFactorAPI mockMultiFactorAPI;
@Captor
private ArgumentCaptor<Callback<List<ValidatePhoneUserResponse>>> callbackArgumentCaptor;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
mainActivity = controller.get();
// Then we need to swap the retrofit api impl. with a mock one
// We store our Retrofit api impl as a static singleton in class RestClient, hence:
RestClient.setApi(mockMultiFactorAPI);
controller.create();
}
错误是:
现在必须显式声明注释处理器。发现编译类路径的以下依赖项包含注释处理器。请将它们添加到 annotationProcessor 配置中。- auto-service-1.0-rc4.jar (com.google.auto.service:auto-service:1.0-rc4) 或者,设置 android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true 以继续之前的行为。请注意,此选项已弃用,将来会被删除。有关详细信息,请参阅https://developer.android.com/r/tools/annotation-processor-error-message.html 。
我添加了这些行来漱口:
dependencies {
implementation 'org.robolectric:robolectric:4.3'
implementation "org.mockito:mockito-core:1.10.19"
implementation 'org.hamcrest:hamcrest-library:1.1'
}
在gradle.Madule:
android{
testOptions {
unitTests {
includeAndroidResources = true
}
} }
在 gradle.app 中:
dependencies{
classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
}
在 gradle.propertice 中:
android.enableUnitTestBinaryResources=true
android.enableAapt2=false
慕标5832272
相关分类