Despite lack of official support for Junit5 in Android Studio (as of ver 4.2.2), running unit test from within the studio, by right-clicking '(test)' folder in Project:Android tool window & choosing "Run 'Tests in...'" for example, executes both JUnit4 and 5 tests.
However, running unit test from command line by executing "gradlew test" runs only JUnit4 tests.
See sample github project which demonstrates it. For details on running tests from command line & location of report files see here.
I looked how android studio runs the tests, but it doesn't execute "gradlew test". instead, it runs gradle tasks "[:app:generateDebugSources, :app:compileDebugSources, :app:createMockableJar, :app:compileDebugUnitTestSources]" (from idea.log) and then executes java jars:
/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
Any idea how to configure gradle "test" task to run JUnit5?
Do you have
test {
useJUnitPlatform()
}
in your build.gradle file?
Related
Having an android library project working fine with AS 4.1.2.
Just installed Android studio (fox) 2020.3.1 patch 3 without change anything (except set the sdk jre to java 8, version 18.6.0_60, since the project is using JavaVersion.VERSION_1_8).
with new AS(fox) the build and run is fine, but the it has issue with unit test and coverage test.
when run unit test, the test will pass but showing some error log:
Caused by: java.lang.IllegalStateException: Cannot process instrumented class com/push/NotificationManager. Please supply original non-instrumented classes.
when try to run the coverage test, it can only do it through the Rnu xxxtest with coverage
not like in AS 4.1.2, it can run the coverage test from Gradle pane/tasks:
also in AS 4.1.2 it could view the coverage test report in the build/report/jacoco folder:
While in new AS(fox) it fails a lot with test events were not not received
and in new AS(fox), in the build/report folder, it could not find the jacoco folder for the result (the html file tells what is the coverage test result, i.e how is branches covered).
the related dependencies:
Gradle: classpath "com.android.tools.build:gradle:4.0.0"
distributionUrl=https://services.gradle.org/distributions/gradle-6.8.3-bin.zip
test:
classpath "org.jacoco:org.jacoco.core:0.8.1"
testImplementation "junit:junit:4.12"
testApi "org.robolectric:robolectric:4.3"
Question
How to resolve the Please supply original non-instrumented classes error in AS (fox)?
How to resolve the test events were not not received?
Where is the jacoco coverage test result html, which shows the coverage percentage details?
Has anyone attempted to integrate jest unit tests with TFS 2015? I tried to use Chutzpah Test Adapter (https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe?SRC=VSIDE) however it's not able to recognize jest. I receive below error:
Can't find variable Jest
When I run the unit tests through "npm test" I get the results. However to integrate with TFS 2015 I need a test runner which can run Jest unit test so that I can run the unit tests in conjunction with vstest.console.exe which the TFS 2015 provides so it can manage build results and publish results in the build summary report.
Any help would be appreciated!!
Any test runner which can run tests using below command should work (considering VS 2015 installed on the system):
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "\test.js" /UseVsixExtensions:true
Extending on Merlin's answer, here is how I've implemented publishing jest test results AND code coverage to TFS2015 vNext builds (I am using create-react-app boilerplate):
First install required packages on the Server you are running your Agent on:
npm install -g jest-json-to-tap
npm install -g tap-xunit
configure jest to output json, by changing in package.json the "test" task to:
"test": "react-scripts test --env=jsdom --json",
configure jest options in package.json:
"jest": { "coverageReporters": ["cobertura"] }
created a vNext build (TFS2015v4) with the following tasks:
a. "npm" task, command=run, arguments=test -- --coverage | jest-json-to-tap | tap-xunit > TEST-result.xml
b. "publish test results" task, format=JUnit
c. "public code coverage results" task, code coverage tool=Cobertura, Summary file=$(Build.Repository.LocalPath)\coverage\cobertura-coverage.xml
make sure your build's "Variables" include setting the environment variable "CI"="true"
NOTES:
- test results will not include times nor assemblies - something to extend for the future...
Voila'! Running this build will correctly publish the test results and code coverage stats, as well as report artifacts.
I'm not sure about jest, but there's a neat npm package that can convert TAP based results to xUnit XMLformat, and then you can publish that to TFS.
Take a look at tap-xunit.
I had a build environment where javascript testing was done by various tools and frameworks (AVA, Mocha, Jasmine etc). We decided to export them all to TAP format, run them throw tap-xunit and then publish to TFS.
Basically, you need something like this:
npm test | tap-xunit > results.xml
You pipe the results to tap-xunit and save them to an XML. This gives you an XML formatted as xUnit that you can publish to TFS. If you're running TFS 2015, I strongly recommend going with vNext builds, a lot easier to get these running. Check the "Publish Test Results" build step.
If you are running with XAML build, this link will help you: Javascript Unit Tests on Team Foundation Service with Chutzpah
If you are running with vNext build, please try the detail steps mentioned with Jasmine.JS test(also a kind of JavaScript test ) in this blog.
i've renamed my test folder to "test". Before it was set to AndroidTest and everything works. But i have a task from my superior that the test folder must be called "test". After i renamed the folder to test in android studio the test stopped running so i went into the run configuration for the test and specified teh package name but that did not help. Here are some details on issue:
and here is the build configuration i am running for the test:
The manifest does not have anything about test in it. This is just a dummy project i made. Do i need to enter something in the manifest ?
After reading the article provided in the comments i thought i'd share how one might resolved the issue:
Android studio does not know how to respond to our test runner unless we tell it. so i made a gradle task like the following:
when you run this gradle task it will run all test cases.
To explain, here we will cleanTest (which cleans all previous tests) then we will run the test task (its like doing gradle test on command line to run test). The test dont run again if they are successful so if you give it the option of --rerun-tasks then it will return the same test task. As for the --tests * option its used to specify which tests you want to run. in my case it was everything but you can specify a class path or even down to the method level here. very useful. so its like running this on the command line: gradle test --rerun-tasks
I can't for the life of me find documentation or a tutorial for kicking off mocha unit tests in Visual Studio Online builds.
I have node.js app that is building in VSO and being deployed to Azure. That all works wonderfully. I can't seem to figure out how to kick off the spec files through the build process.
How is this done? Is there documentation available somewhere that I'm missing.
Assume you have setup Mocha tests with your package.json, i.e. you run tests with npm test. For more information, refer to https://docs.npmjs.com/cli/test.
In your Visual Studio Online build/release:
Add a "npm" task to install JUnit reporter
Run custom command install mocha-junit-reporter
Add a "npm" task
Run custom command test -- --reporter mocha-junit-reporter
Tips: You may want to increase timeout by adding --timeout 30000 because the build agent maybe running slower than your dev box
Then, add a "Publish Test Results" task
Set "Test result format" to "JUnit"
Check the box on "Continue on error"
Under "Control Options" > "Run this task", set it to "Even if a previous task has failed, unless the build was canceled"
Queue a build, you should see Mocha test results in your VSO build.
BONUS! You can also add code coverage to your Mocha run with nyc (formerly known as Istanbul)
On top of the steps above:
Install Istanbul locally to your package.json
Run npm install nyc--save-dev
Modify your scripts in package.json
Update { "scripts": { "test": "nyc --repoter=cobertura mocha" } }
Modify the "npm test" task
Run custom command test -- --reporter mocha-junit-reporter
Add a "Publish Code Coverage Results" task
Set "Code Coverage Tool" to "Cobertura"
Set "Summary File" to $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
Set "Report Directory" to $(System.DefaultWorkingDirectory)/coverage/
Check the box on "Continue on error"
Under "Control Options" > "Run this task", set it to "Even if a previous task has failed, unless the build was canceled"
Add a new build variable NPM_CONFIG_COVERAGE and set it to true
Now you got both unit tests and code coverage results in your build report.
If you've configured you package.json to be able to run tests, adding a npm step that executes npm run test should do it. If you want to publish the test results you need to make sure that Mocha is writing its results to a format understood by Visual Studio Team Services. JUnit format would be a safe bet. Then follow up with a Publish test Results step that uploads the test results.
You can also use the Visual Studio Test Runner, combined with Chutzpah to run your tests, but I suppose that's going to be a lot of additional work to setup and isn't going to add much.
After quite a bit of fiddling around i got it to work by adding a "Command line task" to my build definition, i used the following parameters:
Set Tool to node
Set Arguments to $(Build.SourcesDirectory)\node_modules\jasmine-node\bin\jasmine-node --verbose test\
My tests are under a "test" folder, also make sure you have jasmine-node as a dev dependency
I try to run my first Spock Test inside Eclipse, and it does not work.
I added all the Maven dependencies and plugins in my pom.xml, but when I run my test with jUnit, there is a popup windows with this Warning message : "No jUnit tests found".
Did you already seen this kind of message ?
What config has to be done, in order to run a Spock Test inside Eclipse ?
Thanks a lot.
Its same as running Junit test cases.
Right click on the class and run as 4Junit Test runner. see below for complete configurations and running the spock test.
Running Spock Framework with Eclipse, Gradle, Groovy: Source -
Krzysztof Goralski, blog
-Install Gradle Plugin, check it here
-Install Groovy-Eclipse for Juno or Indigo from Eclipse Marketplace (or maybe Groovy/Grails Tool Suite for Eclipse)
-Install Spock Plugin From Eclipse Marketplace if you want, check it here
-Import Project to Eclipse through Gradle Import
-Add these lines to build.gradle:
apply plugin: ‘groovy’
testCompile ‘org.spockframework:spock-spring:1.0-groovy-2.3’ (for Spring)
this is quite important, version can make some conflicts
-After this *.groovy and *.gradle files will problably looks different, Syntax colour highlightning etc. Remember that you can right click on for eg. build.gradle -> Open with -> Open With Minimalist gradle Editor etc.
-Probably you will need to make additional folder for *.groovy test files
Create new *.groovy file, class
-Basic test example, extends Specification from Spock framework and needs specific Annotations when running with Spring
-Now you can run it with JUnit from Eclipse
For integration tests you can’t use #RunWith(SpringJUnit4ClassRunner.class), and Context should looks like here #ContextConfiguration(locations = [ “/restTestContext.xml” ]) , not {} braces, but [ ]
-Spock can be used for Mocks too. Something like this: Subscriber subscriber1 = Mock() , subscriber1.isActive() >> true , So, remember >> operator for mocks.
Right click on the project > Properties > Java Build Bath > Add External Jars and add spock-core-0.6-groovy-1.8.jar and check if Groovy Libraries are there in Build Path or not. If not click on Add Library and select Groovy Runtime Libraries and restart Eclipse. Now you should be able to run. If still can't Run then try creating New Configuration and change the Test runner to Junit4 and Run it...
Check if the folder your tests are in is a source folder.