首页 > 解决方案 > 在 Android Studio 中运行覆盖率测试时出现 StackOverflowError

问题描述

我一直在我的项目中编写一些测试,当通过命令行使用./gradlew test或从 Android Studio 运行测试时,通过单击“在 java 中运行测试”,所有测试都成功执行。但是,当我尝试使用覆盖率运行所有测试时,出现以下错误,并且有一些测试未执行:

---- IntelliJ IDEA coverage runner ---- 
sampling ...
include patterns:
exclude patterns:
Exception in thread "main" 
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "main"
Class transformation time: 0.823138756s for 3466 classes or 2.3748954298903635E-4s per class
Exception in thread "Thread-2" 
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "Thread-2"
[2021.06.28 16:28:50] (Coverage): Unexpected error: java.lang.StackOverflowError
Exception in thread "Thread-0" 
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "Thread-0"

Process finished with exit code 1

我不知道如何获得有关原因的更多信息,但我想如果正常执行它们时没有问题,那么测试中就没有问题。

我已经修改了这个,但没有这样的选项。此外,IDE 建议通过修改位于/Users/myUser/Library/Application Support/Google/AndroidStudio4.1/studio.vmoptions(对于 Mac)中的文件 studio.vmoptions 来增加堆,但是当我将它从 -Xmx1024m 增加到 -Xmx2048m 或更多时,我遇到了同样的问题。

编辑:单独运行覆盖率的测试时,它们会成功执行。

标签: androidandroid-studiounit-testingtest-coverage

解决方案


推荐阅读