此测试似乎很好并且可以正常工作。
但是,有时候,它永远需要使用blockFirst()方法。
@Test
fun test_getScenarioModel() {
doReturn(MockDownloader({ File("abc.zip") })).whenever(downloaderFactory).newDownloader(
fileStore = any(),
zipUrl = anyString(),
resourceMappingModel = anyOrNull()
)
whenever(fileStore.scenarioFile)
.thenReturn(null)
.thenReturn(scenarioJsonFile)
val actual = scenarioProvider.getScenario().blockingFirst()
val inOrder = inOrder(fileStore, downloaderFactory)
inOrder.verify(fileStore).scenarioFile
inOrder.verify(downloaderFactory).newDownloader(any(), anyString(), anyOrNull())
assertNotNull(actual)
assertNotNull(actual.result)
}
getScenario看起来像这样:
fun getScenario(): Observable<ResultOrException<File>> {
return scenarioModelResultSubject
.doOnNext {
logForDebug { "getScenarioModel(), doOnNext - uniqueId : $uniqueId, result : $it" }
}
.doOnError {
logForDebug { "getScenarioModel(), doOnError - uniqueId : $uniqueId, result : $it" }
}
.doOnComplete {
logForDebug { "getScenarioModel(), doOnComplete" }
}
.doOnSubscribe {
scenarioModelRequestSubject.onNext(scenarioRequestId.get().toString())
}
}
我不知道此测试有什么问题。 也许是机器人问题? https://github.com/robolectric/robolectric/issues/3721
如果我多次运行它,它将始终挂起。 我设置超时并附加错误日志:
Error Message
org.junit.runners.model.TestTimedOutException: test timed out after 10000 milliseconds
Stacktrace
org.junit.runners.model.TestTimedOutException: test timed out after 10000 milliseconds
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
at io.reactivex.internal.observers.BlockingBaseObserver.blockingGet(BlockingBaseObserver.java:71)
at io.reactivex.Observable.blockingFirst(Observable.java:5121)
at com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getScenarioModel(InteractiveMediaResourceManagerTest.kt:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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 org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:601)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
Standard Output
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getResourceMetaFileFromRemote: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_downloadMediaFiles: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getScenarioMetaFileFromCache: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_downloadMediaFilesFailInThird: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getScenarioModel: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getScenarioModelFromFileCache: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getResourceMetaFileFailed: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getResourceMetaFileFromCache: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_getScenarioMetaFileFromServer: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'
[Robolectric] com.mycommyhome.android.interactivemedia.manager.InteractiveMediaResourceManagerTest.test_unacceptableVersion: sdk=25; resources=binary
W/PackageParser: No actions in intent filter at /home/www/data/jenkins/jenkins_home/workspace/com.mycommycom2.android_myandroid_PR_auto-test-beta-me-pr-large-2/build/intermediates/apk_for_local_test/betaReleaseUnitTest/packageBetaReleaseUnitTestForUnitTest/apk-for-local-test.ap_ Binary XML file line #2525
I/MonitoringInstr: Instrumentation started!
I/MonitoringInstr: Setting context classloader to 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04', Original: 'org.robolectric.internal.bytecode.SandboxClassLoader@2c43ae04'