Я не могу соответствующим образом импортировать ActivityTestRule
класс в своем проекте Android Studio. В моем тестовом файле, когда я пишу
public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class);
, ActivityTestRule
становится красным и говорит: «Не удается разрешить символ« ActivityTestRule »».
Как это исправить?
Вот мой build.gradle
(Модуль: приложение):
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "android.example.com"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}
А вот класс, в который я хочу импортировать ActivityTestRule
. (Внутри android.example.com (androidTest)
:
package android.example.com;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ActivityInputOutputTest {
@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class);
}