如何让 android studio "gradlew test" 执行 junit5 测试?

how to make android studio "gradlew test" execute junit5 tests?

尽管 Android Studio(从版本 4.2.2 开始)缺少对 Junit5 的官方支持,运行在工作室中通过右键单击“(测试)”进行单元测试Project:Android 工具 window 中的文件夹并选择“运行 'Tests in...'”,例如,执行 JUnit4 和 5 测试。 然而,运行通过执行“gradlew test”从命令行进行单元测试运行仅 JUnit4 测试。

参见示例 github project which demonstrates it. For details on running tests from command line & location of report files see here

我查看了 android studio 运行s 测试的方式,但它没有执行“gradlew 测试”。相反,它 运行s gradle 任务“[:app:generateDebugSources, :app:compileDebugSources, :app:createMockableJar, :app:compileDebugUnitTestSources]”(来自 idea.log)然后执行 java罐子:

/home/grzeg/Android/android-studio/jre/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/home/grzeg/Android/android-studio/lib/idea_rt.jar=37775:/home/grzeg/Android/android-studio/bin -Dfile.encoding=UTF-8 -classpath /home/grzeg/Android/android-studio/lib/idea_rt.jar:/home/grzeg/.m2/repository/org/junit/platform/junit-platform-launcher/1.7.1/junit-platform-launcher-1.7.1.jar:/home/grzeg/.m2/repository/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar:/home/grzeg/.m2/repository/org/junit/platform/junit-platform-engine/1.7.1/junit-platform-engine-1.7.1.jar:/home/grzeg/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/home/grzeg/.m2/repository/org/junit/platform/junit-platform-commons/1.7.1/junit-platform-commons-1.7.1.jar:/home/grzeg/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.7.1/junit-jupiter-engine-5.7.1.jar:/home/grzeg/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.7.1/junit-jupiter-api-5.7.1.jar:/home/grzeg/.m2/repository/org/junit/vintage/junit-vintage-engine/5.7.1/junit-vintage-engine-5.7.1.jar:/home/grzeg/.m2/repository/junit/junit/4.13/junit-4.13.jar:/home/grzeg/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/grzeg/Android/android-studio/plugins/junit/lib/junit5-rt.jar:/home/grzeg/Android/android-studio/plugins/junit/lib/junit-rt.jar:/home/grzeg/Android/Sdk/platforms/android-30/data/res:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/intermediates/javac/debug/classes:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/intermediates/compile_and_runtime_not_namespaced_r_class_jar/debug/R.jar:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/tmp/kotlin-classes/debugUnitTest:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/tmp/kotlin-classes/debug:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/generated/res/resValues/debug:/home/grzeg/.gradle/caches/modules-2/files-2.1/junit/junit/4.13.2/8ac9e16d933b6fb43bc7f576336b8f4d7eb5ba12/junit-4.13.2.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.junit.platform/junit-platform-commons/1.7.1/7c49f0074842d07f4335de2389d624a7437d1407/junit-platform-commons-1.7.1.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-params/5.7.1/6f81b3c053433a8a40a378d2b4f056c5c31e50ff/junit-jupiter-params-5.7.1.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-api/5.7.1/a7261dff44e64aea7f621842eac5977fd6d2412d/junit-jupiter-api-5.7.1.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.apiguardian/apiguardian-api/1.1.0/fc9dff4bb36d627bdc553de77e1f17efd790876c/apiguardian-api-1.1.0.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.opentest4j/opentest4j/1.2.0/28c11eb91f9b6d8e200631d46e20a7f407f2a046/opentest4j-1.2.0.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ad78c6a7380ca3f9c7a1398b89fa62f3/junit-1.1.3/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/8fffe810368f55a6a59ebbaf0e9f7aa6/espresso-core-3.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/eb299cf707bde01622cf916a326fd5f8/runner-1.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/bf0b12b25a9ce9740353666617faf3f8/core-1.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/c3fc6e9b1d764a98eebcf0a45115f338/storage-1.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/67c0f4e7eff023867cb4cd50493758f3/monitor-1.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f6269bf09fa88fdbdd5c2efc078c3bfe/core-runtime-2.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/098e3cbb790819957cff896f250a4717/espresso-idling-resource-3.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.5.21/2f537cad7e9eeb9da73738c8812e1e4cf9b62e4e/kotlin-stdlib-1.5.21.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.5.21/cc8bf3586fd2ebcf234058b9440bb406e62dfacb/kotlin-stdlib-common-1.5.21.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/androidx.collection/collection/1.1.0/1f27220b47669781457de0d600849a5de0e89909/collection-1.1.0.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-common/2.3.1/fc466261d52f4433863642fb40d12441ae274a98/lifecycle-common-2.3.1.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/androidx.arch.core/core-common/2.1.0/b3152fc64428c9354344bd89848ecddc09b6f07e/core-common-2.1.0.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/androidx.annotation/annotation/1.2.0/57136ff68ee784c6e19db34ed4a175338fadfde1/annotation-1.2.0.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/androidx.constraintlayout/constraintlayout-solver/2.0.1/30988fe2d77f3fe3bf7551bb8a8b795fad7e7226/constraintlayout-solver-2.0.1.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/a8e78915166aa0074d6b796b6207670d/core-ktx-1.6.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/a8e78915166aa0074d6b796b6207670d/core-ktx-1.6.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/a8e78915166aa0074d6b796b6207670d/core-ktx-1.6.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/c78e2c0af5afa33232d9367e0579742a/material-1.4.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/c78e2c0af5afa33232d9367e0579742a/material-1.4.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/c78e2c0af5afa33232d9367e0579742a/material-1.4.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/a9311d74d80edcfc384ea90c9cbb4fb3/constraintlayout-2.0.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/a9311d74d80edcfc384ea90c9cbb4fb3/constraintlayout-2.0.1/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/a9311d74d80edcfc384ea90c9cbb4fb3/constraintlayout-2.0.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d782081d97e8f420d203a315c65d750/appcompat-1.3.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d782081d97e8f420d203a315c65d750/appcompat-1.3.1/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d782081d97e8f420d203a315c65d750/appcompat-1.3.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/dafeb60989f149d261f75912da5819c3/viewpager2-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/dafeb60989f149d261f75912da5819c3/viewpager2-1.0.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/dafeb60989f149d261f75912da5819c3/viewpager2-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ff953813e061668d7ca6bd69b08e4cf3/fragment-1.3.6/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ff953813e061668d7ca6bd69b08e4cf3/fragment-1.3.6/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ff953813e061668d7ca6bd69b08e4cf3/fragment-1.3.6/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/43ca32ca07dcfaf0937dbabca8cde04b/activity-1.2.4/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/43ca32ca07dcfaf0937dbabca8cde04b/activity-1.2.4/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/85bdfd2364ffc1836850c08a38d50e68/appcompat-resources-1.3.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/85bdfd2364ffc1836850c08a38d50e68/appcompat-resources-1.3.1/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/85bdfd2364ffc1836850c08a38d50e68/appcompat-resources-1.3.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/715842898e8d0f21c004cfc21e10f9e2/drawerlayout-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/715842898e8d0f21c004cfc21e10f9e2/drawerlayout-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/8e6a20d7fc9c099ccd7eba17798bb58f/coordinatorlayout-1.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/8e6a20d7fc9c099ccd7eba17798bb58f/coordinatorlayout-1.1.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/8e6a20d7fc9c099ccd7eba17798bb58f/coordinatorlayout-1.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d46647d828d9f08f8e88e5942790788/dynamicanimation-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d46647d828d9f08f8e88e5942790788/dynamicanimation-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f953ab4f37885764354d84ddfde52cef/recyclerview-1.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f953ab4f37885764354d84ddfde52cef/recyclerview-1.1.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f953ab4f37885764354d84ddfde52cef/recyclerview-1.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/1d8550c1f5de451c55fc6403408c54e6/transition-1.2.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/1d8550c1f5de451c55fc6403408c54e6/transition-1.2.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/1d8550c1f5de451c55fc6403408c54e6/transition-1.2.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/31a64ca6ed8676f803ec755f43a77806/vectordrawable-animated-1.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/31a64ca6ed8676f803ec755f43a77806/vectordrawable-animated-1.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f04385de59c26420d58d147a9a74fe51/vectordrawable-1.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f04385de59c26420d58d147a9a74fe51/vectordrawable-1.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/35b89a7df077b7fd54f833295eaf549b/viewpager-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/35b89a7df077b7fd54f833295eaf549b/viewpager-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f2e5b1206570a82806e1a197ad24a53b/legacy-support-core-utils-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/f2e5b1206570a82806e1a197ad24a53b/legacy-support-core-utils-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/bcf16181c4de1d212fa3db965560e89d/loader-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/bcf16181c4de1d212fa3db965560e89d/loader-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/5db7002fd679cf8fc5b68e26cfdd44d3/customview-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/5db7002fd679cf8fc5b68e26cfdd44d3/customview-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ba1d9cdeace3374a3d1f11cb4c3f7039/core-1.6.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ba1d9cdeace3374a3d1f11cb4c3f7039/core-1.6.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/ba1d9cdeace3374a3d1f11cb4c3f7039/core-1.6.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6beb34cd66cfb7058da4244864872e09/cursoradapter-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6beb34cd66cfb7058da4244864872e09/cursoradapter-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/112d19ed6f1e45d7592b5c2efe66c21b/lifecycle-viewmodel-savedstate-2.3.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/112d19ed6f1e45d7592b5c2efe66c21b/lifecycle-viewmodel-savedstate-2.3.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/667b1ae5e8f10d0da20d4ac6a4548ab6/savedstate-1.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/667b1ae5e8f10d0da20d4ac6a4548ab6/savedstate-1.1.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/667b1ae5e8f10d0da20d4ac6a4548ab6/savedstate-1.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/b46b3f9f320747dbae98e35027f70956/cardview-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/b46b3f9f320747dbae98e35027f70956/cardview-1.0.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/b46b3f9f320747dbae98e35027f70956/cardview-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/b8b2e3b141c865387d31f833098d4c29/lifecycle-runtime-2.3.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/b8b2e3b141c865387d31f833098d4c29/lifecycle-runtime-2.3.1/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/b8b2e3b141c865387d31f833098d4c29/lifecycle-runtime-2.3.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6a605a23ec971aaf0adfa6c7baa84e76/versionedparcelable-1.1.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6a605a23ec971aaf0adfa6c7baa84e76/versionedparcelable-1.1.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d0e5509430d526216677a7e0712ffcd/lifecycle-viewmodel-2.3.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d0e5509430d526216677a7e0712ffcd/lifecycle-viewmodel-2.3.1/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/6d0e5509430d526216677a7e0712ffcd/lifecycle-viewmodel-2.3.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/7565da836257268c70c5556d1df8a86b/lifecycle-livedata-2.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/7565da836257268c70c5556d1df8a86b/lifecycle-livedata-2.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/d1d24109638c6dd67c123b6cd4bcd859/lifecycle-livedata-core-2.3.1/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/d1d24109638c6dd67c123b6cd4bcd859/lifecycle-livedata-core-2.3.1/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/c05c2560aa638e51e1584e20fc898d4a/core-runtime-2.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/c05c2560aa638e51e1584e20fc898d4a/core-runtime-2.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/467156583574eb755c4e2afa393e7e04/interpolator-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/467156583574eb755c4e2afa393e7e04/interpolator-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/43a76a240df6409a668896b320cdb11f/documentfile-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/43a76a240df6409a668896b320cdb11f/documentfile-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/006f75501ee49bd5eb21e79e4363589a/localbroadcastmanager-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/006f75501ee49bd5eb21e79e4363589a/localbroadcastmanager-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/76cf6e48a6f215ca02fb8be5d7ec1d75/print-1.0.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/76cf6e48a6f215ca02fb8be5d7ec1d75/print-1.0.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/transforms-2/files-2.1/2309c301d9c715399ce59dfc6758a6c1/annotation-experimental-1.1.0/jars/classes.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/2309c301d9c715399ce59dfc6758a6c1/annotation-experimental-1.1.0/res:/home/grzeg/.gradle/caches/transforms-2/files-2.1/2309c301d9c715399ce59dfc6758a6c1/annotation-experimental-1.1.0/AndroidManifest.xml:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.junit.jupiter/junit-jupiter-engine/5.7.1/7fcfa59c5533abb41f86b1408960737eeaf1f49f/junit-jupiter-engine-5.7.1.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.junit.platform/junit-platform-engine/1.7.1/d276a968c57f5d60a421dedd1f8b6ca2fae09e86/junit-platform-engine-1.7.1.jar:/home/grzeg/.gradle/caches/modules-2/files-2.1/org.junit.vintage/junit-vintage-engine/5.7.1/8184800e1a38965b3fb62a104458678835311e94/junit-vintage-engine-5.7.1.jar:/home/grzeg/.gradle/caches/transforms-2/files-2.1/92ab5f6ce5f14aa9ae87bcae36c1ca6d/tracing-1.0.0/jars/classes.jar:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/intermediates/java_res/debugUnitTest/out:/home/grzeg/Android/AndroidStudioProjects/BugReport/app/build/intermediates/java_res/debug/out:/home/grzeg/.gradle/caches/transforms-2/files-2.1/46679f6f14f1cc8428e02f4c9fc1a544/android.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 @w@/tmp/idea_working_dirs_junit.tmp @/tmp/idea_junit.tmp -socket35491

知道如何将 gradle“测试”任务配置到 运行 JUnit5 吗?

你有吗

test {
    useJUnitPlatform()
}

在您的 build.gradle 文件中?