[英]AndroidX Espresso Test: No tests were found and Empty test suite
I am trying to run src/androidTest which is Instrument test in my Android Project which uses AndroidX libraries, but I am getting No tests were found
error and Empty test suite
log.我正在尝试在我的使用AndroidX库的 Android 项目中运行src/androidTest ,它是仪器测试,但我收到未
No tests were found
错误和Empty test suite
日志。
I have checked all samples and documents which are using AndroidX libraries are doing same.我检查了所有使用 AndroidX 库的示例和文档都在做同样的事情。
I have tried to setup Edit Configurations
based on following link https://stackoverflow.com/a/53715513/1826656 But still no luck.我尝试根据以下链接设置
Edit Configurations
https://stackoverflow.com/a/53715513/1826656但仍然没有运气。
Am I doing anything wrong?我做错了什么吗? or missing any steps?
或缺少任何步骤?
Please check this image for Test Run log请检查此图像以获取测试运行日志
MainActivityTest.java
Code: 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 file dependencies: 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'
}
You have a typo in your defaultConfig.您的 defaultConfig 中有错字。 It should probably be:
大概应该是:
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
In my case, I also struggled to run UI tests.就我而言,我也很难运行 UI 测试。 Checking (and trying) most of the things in similar topics gave no results for me.
检查(并尝试)类似主题中的大部分内容对我来说没有任何结果。 Finally I ran my instrumentation tests via gradle command:
最后,我通过 gradle 命令运行了我的仪器测试:
gradlew connectedProdDebugAndroidTest
or (if you want to run single test, or tests in a single class)或(如果您想运行单个测试,或在单个类中进行测试)
gradlew connectedProdDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class={package.class}#{methodName}
After running tests by command, somehow, it became possible to run them by dedicated button.通过命令运行测试后,不知何故,可以通过专用按钮运行它们。
对我来说,在确保所有依赖项都可用后,将 targetSdk 从 30 更改为较低版本解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.