[英]android espresso testing : empty test suite. no tests were found
[英]AndroidX Espresso Test: No tests were found and Empty test suite
我正在尝试在我的使用AndroidX库的 Android 项目中运行src/androidTest ,它是仪器测试,但我收到未No tests were found
错误和Empty test suite
日志。
我检查了所有使用 AndroidX 库的示例和文档都在做同样的事情。
我尝试根据以下链接设置Edit Configurations
https://stackoverflow.com/a/53715513/1826656但仍然没有运气。
我做错了什么吗? 或缺少任何步骤?
请检查此图像以获取测试运行日志
MainActivityTest.java
代码:
import static androidx.test.espresso.Espresso.onView;
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)
@LargeTest
public class MainActivityTest {
@Rule
ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
@Test
public void checkViewsVisibility() {
// verify the visibility of recycler view on screen
onView(withId(R.id.record_list_rv)).check(matches(isDisplayed()));
// verify the visibility of progressbar on screen
onView(withId(R.id.progressBar)).check(matches(isDisplayed()));
// verify the visibility of no data TextView on screen By default it should be GONE
onView(withId(R.id.no_data_tv)).check(matches(isDisplayed()));
onView(withId(R.id.no_data_tv)).check(matches(withText("No Data")));
onView(withId(R.id.no_data_tv)).perform(typeText("No Data"));
}
}
Gradle 文件依赖项:
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunne"
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
}
您的 defaultConfig 中有错字。 大概应该是:
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
就我而言,我也很难运行 UI 测试。 检查(并尝试)类似主题中的大部分内容对我来说没有任何结果。 最后,我通过 gradle 命令运行了我的仪器测试:
gradlew connectedProdDebugAndroidTest
或(如果您想运行单个测试,或在单个类中进行测试)
gradlew connectedProdDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class={package.class}#{methodName}
通过命令运行测试后,不知何故,可以通过专用按钮运行它们。
对我来说,在确保所有依赖项都可用后,将 targetSdk 从 30 更改为较低版本解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.