The current app I am developing need some integration tests. I decided to write some UI tests in espresso with AndroidJUnitRunner but unfortunately i run into some problems that I can either solve nor understeand. I hoped to find help in your hints and explanation.
For first I try just to run simple activity and check some value just to get it to work, so the code example is short for now. All dependencies, gradle.build and logcat are posted below. If you need more details to help me, please let me know. The IDE I use is intellij.
This is the logcat:
java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.wintermute.gmassistant.test/androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner}: java.lang.InstantiationException: java.lang.Class<androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner> has no zero argument constructor
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6395)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.InstantiationException: java.lang.Class<androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner> has no zero argument constructor
at java.lang.Class.newInstance(Native Method)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6391)
The test class looks as following:
package com.wintermute.gmassistant.database.dao;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.wintermute.gmassistant.R;
import com.wintermute.gmassistant.client.FileBrowser;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test FileBrowser.
*/
@RunWith(AndroidJUnit4.class)
public class FileBrowserTest
{
@Rule
public ActivityScenarioRule<FileBrowser> activityScenarioRule = new ActivityScenarioRule<>(FileBrowser.class);
@Test
void test()
{
onView(withId(R.id.select_directory)).perform(typeText("Select current directory"));
}
}
This is my build.gradle
apply plugin: 'com.android.application'
android {
android {
lintOptions {
abortOnError false
}
}
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.wintermute.gmassistant"
minSdkVersion 27
targetSdkVersion 29
versionCode 1
versionName "1.0"
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.1.0'
//lombok
implementation 'org.projectlombok:lombok:1.18.10'
implementation 'com.google.android.material:material:1.0.0'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
//REST Client
implementation 'com.android.volley:volley:1.1.1'
//color picker
implementation 'com.github.skydoves:colorpickerpreference:2.0.0'
//Guava
implementation 'com.google.guava:guava:28.1-android'
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:hamcrest-library:2.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}
Any ideas why it happens? I would love if you could explain it to me so I can understeand it.
Aucun commentaire:
Enregistrer un commentaire