gpt4 book ai didi

java - 没有仪器注册!必须在注册工具下运行

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:47 24 4
gpt4 key购买 nike

我无法在我的设备上运行测试并收到错误 未注册仪器!必须在注册仪器下运行。这是我的测试类:

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@gmail.com"), closeSoftKeyboard());
onView(withId(R.id.etPassword)).perform(typeText("asdgfhj"), closeSoftKeyboard());
onView(withText("The username and password combination is invalid")).check(matches(isDisplayed()));
}
}

这是我的构建 gradle。我已经添加了所有测试依赖项,但没有任何效果。我已经完成了此处描述的所有操作:Run espresso in ActivityInstrumentationTestCase2 ,在默认配置中添加了 AndroidJUnitRunner。

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'
}

最佳答案

您必须在 build.gradle (app) 中使用 ALL AndroidX 依赖项

// 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'

所以改变这一行

androidTestImplementation 'com.android.support.test:runner:1.0.2'

对此

androidTestImplementation 'androidx.test:runner:1.1.1'

并且不要忘记在您的 defaultConfig 中使用 AndroidX testInstrumentationRunner

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

关于java - 没有仪器注册!必须在注册工具下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53212955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com