且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android Studio 3.1 中的单元测试配置中断

更新时间:2023-11-16 21:47:22

正如这位 bug 评论者所指出的:https://issuetracker.google.com/issues/77605097#comment7

禁用 Gradle 的按需配置"功能(在设置:构建、执行和部署:编译器中)是一种可行的解决方法.

自从我这样做后,我的单元测试都可以再次运行了.

I updated to Android Studio 3.1 and as suggested by Android Studio also:

  • Updated the Android gradle plugin to 3.1.0 from 2.3.0 (also tried the new 3.1.1, the problem persists)
  • Updated the buildToolsVersion to 27.0.3
  • Downloaded the Android 8.1 API 27 with the SDK manager.

I am using the JDK 8.

My previous Android Studio build configuration "Core tests" which just ran all tests in one module now says:

Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.5.1-all.zip'.

My set up:

The exact exception as shown in the ide:

My full source code: https://github.com/Leejjon/BluffPoker

Apparently the same Nullpointer occurs when running this on the command line: gradle :core:test This command will fail with the same NullPointer. Doing a test on the root project like gradle test will run fine. I can also deploy the app on my Android phone. This is probably not IntelliJ related but the Android gradle plugin 3.1.0 breaking the ability to run the gradle :core:test command.

TLDR: Running any gradle task in the core module like gradle :core:sometask seems to result in a null pointer since Android gradle plugin 3.1.0.

My workaround for now is to use the gradle test command to run all tests in all modules and study the generated html pages by junit (found in BluffPoker\core\build\reports\tests\test\index.html) to troubleshoot whether they are failing.

As this bug commenter pointed out: https://issuetracker.google.com/issues/77605097#comment7

disabling the "configure on demand" feature of Gradle (in Settings: Build, Execution, and Deployment: Compiler) is a viable workaround.

Since I did this my Unit tests are all working again.