Issue
I can't run test on my device and getting error No instrumentation registered! Must run under a registering instrumentation.
Here is my test class:
package com.pecode.itrustyou.ui.login;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import com.pecode.itrustyou.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.rule.ActivityTestRule;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class LoginActivityTest {
@Rule
public ActivityTestRule<LoginActivity> activityTestRule = new ActivityTestRule<>(LoginActivity.class);
@Test
public void enterInvalidPassword() {
onView(ViewMatchers.withId(R.id.etEmail)).perform(typeText("[email protected]"), closeSoftKeyboard());
onView(withId(R.id.etPassword)).perform(typeText("asdgfhj"), closeSoftKeyboard());
onView(withText("The username and password combination is invalid")).check(matches(isDisplayed()));
}
}
Here is my build gradle. I've added all test dependencies but nothing working. And I've done everything that is described here: Run espresso in ActivityInstrumentationTestCase2, added AndroidJUnitRunner in default configs.
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
buildToolsVersion '28.0.3'
compileSdkVersion 28
defaultConfig {
applicationId "com.pecode.itrustyou"
minSdkVersion 21
targetSdkVersion 28
versionCode 4
versionName "0.1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
buildConfigField "String", "BASE_URL", '"https://test-itrustyouservices.azurewebsites.net"'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "BASE_URL", '"https://api.itrustyou.io"'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
android.applicationVariants.all { variant ->
variant.outputs.all {
def formattedDate = new Date().format('dd.MM.yyyy')
outputFileName = "ITrustYou-${formattedDate}.apk"
}
}
dataBinding {
enabled = true
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
///viewModel
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
//recyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'
//constraint layout
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:28.0.0'
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
//circleImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'
///barcode
implementation(name: 'LibPdf417Mobi', ext: 'aar')
//ui
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
//eventbus
implementation 'org.greenrobot:eventbus:3.1.1'
//support
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
//CrashLytics
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}
//test
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
}
Solution
You must use ALL AndroidX dependencies in your build.gradle (app)
// Core library
androidTestImplementation 'androidx.test:core:1.1.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
// Espresso dependencies
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
So change this line
androidTestImplementation 'com.android.support.test:runner:1.0.2'
to this
androidTestImplementation 'androidx.test:runner:1.1.1'
and don't forget to use AndroidX testInstrumentationRunner in your defaultConfig
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Answered By - crubio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.