运行 Android 插桩测试失败
Run Android instrumented tests fail
我尝试为我的 Android 应用程序 (Java) 实施一些单元测试和仪器测试,我的单元测试工作正常但仪器测试失败:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ExampleInstrumentedTest {
@Rule
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class);
@Test
public void checkIfCategoriesIsNotEmpty() {
onView(withId(R.id.header_left_layout)).perform(click());
onView(withId(R.id.list_view)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
ListView list_categories = (ListView) view;
ListAdapter adapter = list_categories.getAdapter();
Assert.assertTrue(adapter.getCount() > 0);
}
});
}
}
当我尝试 运行 我的测试时,我得到了这个错误:
"Run Android instrumented tests using Gradle" option was ignored because this module type is not supported yet.
我在 build.config 文件中的实现是:
// UNIT TEST
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
// INSTRUMENTED TEST
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
解决方案是排除模块:protobuf-lite :
androidTestImplementation('androidx.test.espresso:espresso-contrib:3.4.0') {
exclude module: "protobuf-lite"
}
我也刚 运行 遇到这个问题。我在“Android 测试”部分下的 Android Studio Bumblebee 2021.1.1 release notes 中找到了解决方案。
这基本上相当于取消选中 运行 Android 测试设置中使用 Gradle 的仪器测试旁边的框。这对我有用。
我尝试为我的 Android 应用程序 (Java) 实施一些单元测试和仪器测试,我的单元测试工作正常但仪器测试失败:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ExampleInstrumentedTest {
@Rule
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class);
@Test
public void checkIfCategoriesIsNotEmpty() {
onView(withId(R.id.header_left_layout)).perform(click());
onView(withId(R.id.list_view)).check(new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
ListView list_categories = (ListView) view;
ListAdapter adapter = list_categories.getAdapter();
Assert.assertTrue(adapter.getCount() > 0);
}
});
}
}
当我尝试 运行 我的测试时,我得到了这个错误:
"Run Android instrumented tests using Gradle" option was ignored because this module type is not supported yet.
我在 build.config 文件中的实现是:
// UNIT TEST
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
// INSTRUMENTED TEST
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
解决方案是排除模块:protobuf-lite :
androidTestImplementation('androidx.test.espresso:espresso-contrib:3.4.0') {
exclude module: "protobuf-lite"
}
我也刚 运行 遇到这个问题。我在“Android 测试”部分下的 Android Studio Bumblebee 2021.1.1 release notes 中找到了解决方案。
这基本上相当于取消选中 运行 Android 测试设置中使用 Gradle 的仪器测试旁边的框。这对我有用。