首页 > 解决方案 > java.lang.IllegalStateException:单元测试期间正在关闭

问题描述

最近,我的一些测试开始失败,但有以下例外:

[Robolectric] tests.integration.TourQueryHandlerTest.testLinkedEmployeeAccompanyingNurse: sdk=25; resources=legacy
[Robolectric] NOTICE: legacy resources mode is deprecated; see http://robolectric.org/migrating/#migrating-to-40

java.lang.IllegalStateException: Shutdown in progress

    at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:66)
    at java.lang.Runtime.addShutdownHook(Runtime.java:211)
    at org.robolectric.util.TempDirectory.<init>(TempDirectory.java:23)
    at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:90)
    at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:377)
    at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:252)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
    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.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
    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 com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

在撰写本文时,它似乎只发生在 robolectric 测试中,但并非所有测试都发生,当然也不会同时发生。

我尝试使用我们最好的朋友 Google 进行调查,但到目前为止我还没有找到任何特定于 Android Studio 或 robolectric 的结果

我找到了这个: https ://developer.ibm.com/answers/questions/308650/why-is-the-jvm-failing-to-start-with-javalangilleg/ 它似乎与在已经调用 System.exit() 的进程上添加关闭挂钩;

我正在研究它,但有时测试通过,有时却没有,这很奇怪。

标签: javaandroid-studiorobolectric

解决方案


推荐阅读