[英]Espresso test class not found
我创建了一个基本的 Espresso 测试 class,如下所示:
@LargeTest
@RunWith(AndroidJUnit4.class)
class ConfigurationsActivityTest {
@Rule
public ActivityTestRule<ConfigurationsActivity> mConfigsTestRule =
new ActivityTestRule<>(ConfigurationsActivity.class);
@Test
public void isInView() {
onView(withId(R.id.config_recyclerview)).check(matches(isDisplayed()));
}
}
问题是,当我尝试运行此测试时,我收到以下错误消息:
Class 未找到:“com.name.app.activities.ConfigurationsTest”
我遵循了这个答案: Android Espresso 测试:Class 未找到:...空测试套件并查看我的运行配置。 似乎我的测试是作为单元测试运行的,即使它是一个仪器测试。
当我删除单元测试配置时,会出现另一个问题,这些配置是在我尝试运行我的插桩测试时创建的,并尝试为我的测试 class 创建插桩测试运行配置:向导不允许我 select 我的插桩测试 ZA2F211A29EBC06CBCBDC4上面的测试是测试 class。 问题在这里可视化。
我还看了这个答案: TestCase class not found by Android Studio并确认我在 main/java 和 androidTest/java 中的目录结构是相同的。
此外,当我按照这个问题所做的事情: Android Espresso:“未找到测试”,“进程崩溃”并为包含我的测试 ZA2F2ED4F8EBC42CBB4C21ZD8Z 的整个 package 创建运行配置时,得到:
java.lang.RuntimeException:无法加载 AndroidJUnit4 的委托运行程序“androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner”。
我怀疑这与我的导入或依赖项有关。 以下是两者:
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.13'
testImplementation "org.mockito:mockito-core:3.3.1"
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
}
任何帮助表示赞赏。 谢谢!
规则应该是这样的
@Rule
public ActivityTestRule<ConfigurationsActivity> mConfigsTestRule =
new ActivityTestRule<>(ConfigurationsActivity.class);
测试 class 必须是公开的。 这就是为什么它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.