0

I have written this test in test pakage, for test of a retrofit class, but even before test stars,in addition to unknownable "constants" in @Config, this error is shown:

@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();
}

The error is:

Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration. - auto-service-1.0-rc4.jar (com.google.auto.service:auto-service:1.0-rc4) Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

I've added these lines to gargle to:

dependencies {
    implementation 'org.robolectric:robolectric:4.3'
    implementation "org.mockito:mockito-core:1.10.19"
    implementation 'org.hamcrest:hamcrest-library:1.1'
}

in gradle.Madule:

android{
testOptions {
    unitTests {
        includeAndroidResources = true
    }
}    }

in gradle.app:

dependencies{
    classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
}

in gradle.propertice:

android.enableUnitTestBinaryResources=true
android.enableAapt2=false
Minu
  • 57
  • 6

1 Answers1

0

my problem solved by putting this code in my app.gradle :

dependencies{
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.okhttp3:mockwebserver:3.6.0'
}

and

1) find the location of of your .gradle folder, in Android Studio goto File->Settings and type "gradle" in the search box. You will be able to pick up the correct path there

2)Remove the .gradle directory (mine's location was C:\Users\UserName.gradle), and restart android studio. It will automatically create a new one.

from Android studio: build project error - Failed to complete Gradle execution

Minu
  • 57
  • 6