我已经编写了一些工作正常的检测测试,但是现在获得错误无法在将依赖项升级到之后解决ActivityTestRule错误
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Run Code Online (Sandbox Code Playgroud)
我正在使用android支持版本27.1.1
它与依赖项工作正常
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Run Code Online (Sandbox Code Playgroud) android test-runner android-espresso android-instrumentation
我想将仪器测试作为 CI 管道的一部分运行,但是当我运行测试时,它们会失败,因为无法安装 APK(据我所知):
> Task :app:connectedDebugAndroidTest FAILED
Mar 18, 2022 3:00:59 PM com.google.testing.platform.RunnerImpl run
SEVERE: Test execution failed with fatal error!
com.google.testing.platform.api.plugin.PluginException: Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin.
at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow(PluginLifecycle.kt:216)
at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow$default(PluginLifecycle.kt:205)
at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:92)
at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:88)
at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
at com.google.testing.platform.plugin.PluginLifecycle.onBeforeAll(PluginLifecycle.kt:88)
at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
at com.google.testing.platform.executor.SingleDeviceExecutor.runUnlessCancelled(SingleDeviceExecutor.kt:105)
at com.google.testing.platform.executor.SingleDeviceExecutor.execute(SingleDeviceExecutor.kt:86)
at com.google.testing.platform.RunnerImpl.run(RunnerImpl.kt:108)
at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:80)
at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:79)
at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:66)
at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy.run(NonInteractiveServerStrategy.kt:79)
at com.google.testing.platform.main.MainKt$main$4.invokeSuspend(Main.kt:67)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at …Run Code Online (Sandbox Code Playgroud) 我是一家初创公司的QA.我的开发人员在Android项目中设置了Instrumentation测试.他还设置Jenkins Jobs在CI环境中运行这些测试.
这是在Build - > Invoke Gradle脚本下的Jenkins作业的"Tasks"字段中给出的命令.clean assembleDebug connectedAndroidTest testDebug
我想创建自己的Jenkins作业来运行不同类型的测试.有没有办法可以通过运行"connectedAndroidTest"命令来过滤我的测试?我尝试使用如下所示的shell脚本,但它没有用.adb shell am instrument -w /
我收到以下错误消息:[执行Smoke测试套件] $/bin/bash -xe /var/folders/qr/vtm32_d56vz0hgwg5ppdbswc00007q/T/hudson1779650135635362469.sh + adb shell am instrument -w''class com.draysonwireless.airmapandroid .rewards/BonusTest.java /var/folders/qr/vtm32_d56vz0hgwg5ppdbswc00007q/T/hudson1779650135635362469.sh:line 2:adb:command not found构建步骤'执行shell'将构建标记为失败完成:FAILURE
我的一位QA工程师正在支持具有相当大的代码库和许多不同的SharedPreferences文件的应用程序.前几天他来找我,询问如何在测试运行之间重置应用程序状态,就像它已经卸载 - 重新安装一样.
Espresso(他正在使用)和Android测试框架本身都不支持它,所以我不知道该告诉他什么.使用本机方法清除所有不同的SharedPreferences文件将是一个非常脆弱的解决方案.
如何在仪表期间重置应用程序状态?
我有calabash-android设置与默认场景完美配合(cucumber用于运行测试或calabash-android console进入REPL模式).
但是,在某些情况下,能够连接到已经运行的应用程序非常有用.例如,我将在调试模式下启动应用程序并启动测试以便能够设置断点并检查为什么某些功能在我的方案中不能按预期工作.
当谈到iOS上的Calabash时,这个任务非常简单:当应用程序以捆绑的测试服务器启动时,不需要额外的准备工作,我可以随时附加葫芦.但是,每当我尝试启动应用程序运行的calabash时,Calabash Android似乎都会强制退出应用程序.
它有什么办法吗?
编辑 看起来下面的答案没什么用,但我仍然希望有人(葫芦开发者,你在哪里?)会偶然发现这一天.我花了一些时间自己发现问题,具体问题是:
calabash-android console PATH_TO_APKquery("*")) - 它失败并显示KeepAliveDisconnected消息挖掘更深的细节,我发现实际上运行该start_test_server_in_background shell am instrument与sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner被仪器的后端,并描述其应用到仪器一堆其他标志,使用什么端口等.
如上所述,以下内容将有很大帮助:shell am instrument是否可以附加到正在运行的应用程序?
android cucumber calabash android-instrumentation calabash-android
如何在不手动运行adb命令的情况下让Android Studio(AndroidJunitRunner)清除检测测试之前的应用程序数据?
我发现了android.support.test.runner.AndroidJUnitRunner一种作弊的-它从来没有真正调用connectedCheck或connectedAndroidTest.
从命令行运行时 $ gradle connectedCheck
:MyMainApp:assembleDebug UP-TO-DATE
:MyMainApp:assembleDebugTest UP-TO-DATE
:MyMainApp:clearMainAppData
:MyMainApp:connectedCheck
Run Code Online (Sandbox Code Playgroud)通过单击检测测试配置从IDE内部运行(带有红色/绿色箭头的绿色Android机器人徽标)
**Executing tasks: [:MyMainAppApp:assembleDebug, :MyMainAppApp:assembleDebugTest]**
Run Code Online (Sandbox Code Playgroud)
如您所见,最后一个gradle目标是 assembleDebugTest
我已经添加了一个钩到connectedCheck在build.gradle开始仪表测试之前清除主要的应用程序的数据.
// Run 'adb' shell command to clear application data of main app for 'debug' variant
task clearMainAppData(type: Exec) {
// we have to iterate to find the 'debug' variant to obtain a variant reference
android.applicationVariants.all { variant ->
if (variant.name.equals("debug")) {
def clearDataCommand = ['adb', 'shell', 'pm', …Run Code Online (Sandbox Code Playgroud) gradle android-studio android-gradle-plugin android-instrumentation
我设法让gradle cC工作.我的测试打印出来并记录一行文字.
grep -r text * fails.
Run Code Online (Sandbox Code Playgroud)
哪里是system.out和logging输出?
谢谢
编辑:我找到了单元测试的输出(它在.../app/build/test-results /中).但是对方仍然没有运气.
有没有办法以某种方式保存仪表化测试的输出?
这是我的仪器测试的范围:
...
import androidx.test.rule.ActivityTestRule
@RunWith(AndroidJUnit4::class)
@LargeTest
class InstrumentDialogFragmentTest {
@get:Rule
val activityRule = ActivityTestRule(MainActivity::class.java)
}
Run Code Online (Sandbox Code Playgroud)
我的等级:
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:rules:1.4.0'
Run Code Online (Sandbox Code Playgroud)
我收到此警告:
'ActivityTestRule<T : Activity!>' is deprecated. Deprecated in Java
Run Code Online (Sandbox Code Playgroud) android automated-tests junit4 android-instrumentation deprecation-warning
我想在测试活动中测试一个片段.我添加TestTragmentActivity到androidTest连同AndroidManifest.xml文件.但是,当我尝试通过ActivityTestRule它使用此活动时,会出现以下错误:
java.lang.RuntimeException: Could not launch activity
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:371)
at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:219)
at com.bbm.ui.fragments.StickerPackListFragmentTest.testEmpty(StickerPackListFragmentTest.java:29)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at …Run Code Online (Sandbox Code Playgroud) android unit-testing junit-runner android-espresso android-instrumentation
我开始为我的公司实施仪器测试,以提高我们的代码质量和部署速度。我正在重写应用程序的一个模块,并尝试实施 TDD 原则。我的代码目前无法运行,因此我想将调试器附加到我的仪器测试中以验证其执行情况。除了在每次调试编译时我都会遇到错误Test run failed to complete. Instrumentation run failed due to Process crashed。
通过二分法,我创建了一个仅包含一个模块的简单项目,并启动了作为示例给出的仪器测试。
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.mylibrary.test", appContext.packageName)
}
}
Run Code Online (Sandbox Code Playgroud)
相同的结果。然后我在应用程序模块中启动了相同的仪器测试,令人惊讶的是,调试器已连接并触发了断点。
无法将调试器附加到模块中的仪器测试中?当我运行测试时,该测试有效并得到验证
您将在这里找到我的库的 build.gradle 文件
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.mylibrary'
compileSdk 33
defaultConfig {
minSdk 24
targetSdk …Run Code Online (Sandbox Code Playgroud) android ×8
calabash ×1
cucumber ×1
gradle ×1
junit-runner ×1
junit4 ×1
test-runner ×1
unit-testing ×1