私はエスプレッソを使った簡単なUIテストを実行しようとしていると、すべての私のテストは、同じ例外で失敗します:
java.lang.IllegalStateException:いいえ計装は登録されていません!登録計装の下で実行する必要があります
それはesspressoの使用中の初心者ガイドですここ。私はすでに私に似た質問が、最も関連性の高いものを発見した応答がないここに -私は彼らが私のコードがあるので、ここで全体像を描いていなかったので、それがあると推定。それらはすべて正確に同じエラーで失敗したので、私は1つのテストのみが表示されます:
build.gradle(モジュール:アプリ)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "io.github.vinge1718.myrestaurants"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
dependencies {
testImplementation "org.robolectric:robolectric:3.8"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
}
build.gradle(プロジェクト:MyRestaurant)
buildscript {
repositories {
google()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ここでの補正は、2つのテスト。私はかかわらず、修正スタンド-私はエラーがテストそのものが、構成に関連するどのような方法であるとは思いません
(MainActivityInstrumentationTest.java)
package io.github.vinge1718.myrestaurants;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.rule.ActivityTestRule;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
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.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
public class MainActivityInstrumentationTest {
private String mStringToBetyped;
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Before
public void initValidString() {
// Specify a valid string.
mStringToBetyped = "Portland";
}
@Test
public void validateEditText(){
onView(withId(R.id.locationEditText))
.perform(typeText(mStringToBetyped), closeSoftKeyboard())
.check(matches(withText(mStringToBetyped)));
}
@Test
public void locationIsSentToRestaurantActivity(){
String location = "Portland";
onView(withId(R.id.locationEditText)).perform(typeText(location));
onView(withId(R.id.findRestaurantsButton)).perform(click());
onView(withId(R.id.locationTextView)).check(matches(withText("Here are all the Restaurants near " + location)));
}
}
私は、このエスプレッソセットアップマニュアルを参照して、次の試してみましたが、ここで私は同じエラーを取得しておいてください。
テストの実行を開始
java.lang.IllegalStateException:いいえ計装は登録されていません!登録計装の下で実行する必要があります。androidx.testでandroidx.test.InstrumentationRegistry.getTargetContext androidx.test.rule.ActivityTestRuleで(InstrumentationRegistry.java:101)。(ActivityTestRule.java:144)でandroidx.test.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:50)で.rule.ActivityTestRule。androidx.test.rule.ActivityTestRuleで(ActivityTestRule.java:120)。(ActivityTestRule.java:103)io.github.vinge1718.myrestaurants.MainActivityInstrumentationTestた。(MainActivityInstrumentationTest.java:25)されるjava.langでorg.junit.runnersでorg.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)でjava.lang.reflect.Constructor.newInstance(Constructor.java:334)で.reflect.Constructor.newInstance0(ネイティブメソッド) 。
テストが完了するまで走りました。
ここでエスプレッソの設定に記載されているように私のテスト構成であるドキュメントは:
私は図書館のためであると考えるandroidx
と競合していますcom.android.support.test
。あなたがジェットパックを使用する場合は、あなたがそのようにしたくない場合は、ちょうどあなたの削除、androidxにテストライブラリのすべてを変換しなければならないandroidx
ライブラリをし、すべてを使用しますcom.android.support.test
。で私の最新の答えをチェックノー計装登録エラー:Androidの計装のテストを。このヘルプにあなたを願っています。