gpt4 book ai didi

java - Android Instrumentation 使用 androidx Orchestrator 进行测试部分失败

转载 作者:行者123 更新时间:2023-12-02 04:26:58 26 4
gpt4 key购买 nike

我正在尝试让我们的测试在 androidx Orchestrator 下运行。

它似乎部分有效,但并未找到并运行所有测试。

我已将相关测试代码提取到我在项目 build.gradle 上调用的辅助方法中。

ext.enableTesting = { Project project ->
logger.lifecycle "Enable Testing: " + project.displayName

project.android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// runs pm clear after each test invocation
testInstrumentationRunnerArguments clearPackageData: 'true'
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
animationsDisabled true

unitTests {
includeAndroidResources = true
}
}

useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
}

project.dependencies {
// Tests - Including NoOp
testImplementation 'junit:junit:4.12'

androidTestUtil 'androidx.test:orchestrator:1.2.0'

// Core library
androidTestImplementation 'androidx.test:core:1.2.0'

// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'

// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:truth:1.2.0'

// Mockito
testImplementation "org.mockito:mockito-core:${project.ext.mockitoVersion}"
testImplementation "org.mockito:mockito-android:${project.ext.mockitoVersion}"
androidTestImplementation "org.mockito:mockito-core:${project.ext.mockitoVersion}"
androidTestImplementation "org.mockito:mockito-android:${project.ext.mockitoVersion}"

}
// 'androidx.test.ext:truth:1.2.0' pulls in some conflicting
// versions with other things we need. In particular it has a more
// recent version of guava which then screws up grpc stuff.
project.configurations.all {
resolutionStrategy {
force 'com.google.errorprone:error_prone_annotations:2.1.2',
'com.google.code.findbugs:jsr305:3.0.2',
'com.google.guava:guava:26.0-android',
'org.checkerframework:checker-compat-qual:2.5.3'
}
}
}

我们的 18 个测试通过了,logcat 对这些测试有以下内容:

06-14 03:13:10.129: D/TestExecutor(17920): Adding listener androidx.test.internal.runner.listener.LogRunListener
06-14 03:13:10.129: D/TestExecutor(17920): Adding listener androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener
06-14 03:13:10.129: D/TestExecutor(17920): Adding listener androidx.test.internal.runner.listener.ActivityFinisherRunListener
06-14 03:13:10.129: D/TestExecutor(17920): Adding listener androidx.test.internal.runner.listener.CoverageListener
06-14 03:13:10.135: I/TestRunner(17920): run started: 1 tests
06-14 03:13:10.139: I/TestRunner(17920): started: testSetAvailable(app.impl.AvailabilityManagerTest)
06-14 03:13:11.914: I/TestRunner(17920): finished: testSetAvailable(app.impl.AvailabilityManagerTest)
06-14 03:13:11.924: I/TestRunner(17920): run finished: 1 tests, 0 failed, 0 ignored

但是,另一个包中的测试失败并显示:

06-14 03:15:07.671: D/TestExecutor(28814): Adding listener androidx.test.internal.runner.listener.LogRunListener
06-14 03:15:07.671: D/TestExecutor(28814): Adding listener androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener
06-14 03:15:07.671: D/TestExecutor(28814): Adding listener androidx.test.internal.runner.listener.ActivityFinisherRunListener
06-14 03:15:07.671: D/TestExecutor(28814): Adding listener androidx.test.internal.runner.listener.CoverageListener
06-14 03:15:07.676: I/TestRunner(28814): run started: 1 tests
06-14 03:15:07.676: E/TestRunner(28814): failed: Test mechanism
06-14 03:15:07.677: E/TestRunner(28814): ----- begin exception -----
06-14 03:15:07.677: E/TestRunner(28814): java.lang.IllegalStateException: Unable to send notification, callback is null
06-14 03:15:07.677: E/TestRunner(28814): at androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener.sendTestNotification(OrchestratedInstrumentationListener.java:163)
06-14 03:15:07.677: E/TestRunner(28814): at androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener.testRunStarted(OrchestratedInstrumentationListener.java:94)
06-14 03:15:07.677: E/TestRunner(28814): at org.junit.runner.notification.SynchronizedRunListener.testRunStarted(SynchronizedRunListener.java:35)
06-14 03:15:07.677: E/TestRunner(28814): at org.junit.runner.notification.RunNotifier$1.notifyListener(RunNotifier.java:91)
06-14 03:15:07.677: E/TestRunner(28814): at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
06-14 03:15:07.677: E/TestRunner(28814): at org.junit.runner.notification.RunNotifier.fireTestRunStarted(RunNotifier.java:88)
06-14 03:15:07.677: E/TestRunner(28814): at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
06-14 03:15:07.677: E/TestRunner(28814): at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
06-14 03:15:07.677: E/TestRunner(28814): at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
06-14 03:15:07.677: E/TestRunner(28814): at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
06-14 03:15:07.677: E/TestRunner(28814): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2106)
06-14 03:15:07.677: E/TestRunner(28814): ----- end exception -----
06-14 03:15:07.680: I/TestRunner(28814): started: testMatcherWithMatchFound(app.impl.matcher.MatcherTest)
06-14 03:15:07.681: E/TestRunner(28814): failed: Test mechanism
06-14 03:15:07.681: E/TestRunner(28814): ----- begin exception -----
06-14 03:15:07.681: E/TestRunner(28814): java.lang.IllegalStateException: Unable to send notification, callback is null
06-14 03:15:07.681: E/TestRunner(28814): at androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener.sendTestNotification(OrchestratedInstrumentationListener.java:163)
06-14 03:15:07.681: E/TestRunner(28814): at androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener.testStarted(OrchestratedInstrumentationListener.java:114)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runner.notification.SynchronizedRunListener.testStarted(SynchronizedRunListener.java:49)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runner.notification.RunNotifier$3.notifyListener(RunNotifier.java:121)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runner.notification.RunNotifier.fireTestStarted(RunNotifier.java:118)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.internal.runners.model.EachTestNotifier.fireTestStarted(EachTestNotifier.java:42)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:323)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.Suite.runChild(Suite.java:128)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.Suite.runChild(Suite.java:27)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
06-14 03:15:07.681: E/TestRunner(28814): at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
06-14 03:15:07.681: E/TestRunner(28814): at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
06-14 03:15:07.681: E/TestRunner(28814): at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
06-14 03:15:07.681: E/TestRunner(28814): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2106)
06-14 03:15:07.681: E/TestRunner(28814): ----- end exception -----

此后,不再运行任何测试,并且 Firebase 测试实验室导致构建超时。

对于如何更改以使我们的所有测试运行有什么建议吗?

提前致谢!

最佳答案

事实证明,这是 Orchestration 框架中的一个错误,当前最好的解决方案就是不使用 Orchestration。我为此创建了一个问题:

https://issuetracker.google.com/issues/135574731

关于java - Android Instrumentation 使用 androidx Orchestrator 进行测试部分失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56604180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com