Gradle Android: How to Display test results without using --info

前端 未结 3 1091
梦谈多话
梦谈多话 2021-02-15 12:59

I am running android tests using the Gradle Android plugin and want to see individual test results.

From answers to this Question Gradle: How to Display Test Results in

相关标签:
3条回答
  • 2021-02-15 13:06

    Use Gradle info

    This will print all information from Gradle:

    gradle --info
    

    or Use Android Gradle plugin:

    android.testOptions.unitTests.all {
        // Configure whether failing tests should fail the build
        ignoreFailures false
    
        testLogging {
            events "passed", "skipped", "failed", "standardOut", "standardError"
        }
    }
    

    or Use Gradle directly:

    allprojects {
        tasks.withType(Test) {
            testLogging {
                exceptionFormat "full"
                showCauses true
                showExceptions true
                showStackTraces true
                showStandardStreams true
                events = ["passed", "skipped", "failed", "standardOut", "standardError"]
            }
        }
    }
    

    See: https://github.com/jaredsburrows/android-gradle-java-app-template/blob/master/gradle/compile.gradle#L20

    Output:

    io.github.hidroh.materialistic.data.SessionManagerTest > testView PASSED
    
    io.github.hidroh.materialistic.data.SessionManagerTest > testIsViewFalse PASSED
    
    io.github.hidroh.materialistic.data.SessionManagerTest > testIsViewNull PASSED
    
    io.github.hidroh.materialistic.data.SessionManagerTest > testIsViewTrue PASSED
    
    io.github.hidroh.materialistic.data.SessionManagerTest > testViewNoId PASSED
    

    Source: https://github.com/hidroh/materialistic/blob/master/robolectric.gradle

    Gradle Docs: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/logging/TestLogEvent.html

    0 讨论(0)
  • 2021-02-15 13:09

    For me all the options mentioned in the other answer still printed a lot of verbose information. So despite the requirement that info should not be used, I successfully use the following. For example, if your tests are in the package com.example.android, you can use:

    gradle --info connectedDebugAndroidTest | grep "com\.example\.android\..* >"
    

    Will print e. g.:

     com.example.android.login.LoginActivityTest > enterCredentialsTest[Testing_emulator(AVD) - 9] SUCCESS
    

    And the word "SUCCESS" will be green, which is awesome.

    0 讨论(0)
  • 2021-02-15 13:13

    For Android Studio (tested on com.android.tools.build:gradle:2.1.0 and gradle version gradle-2.10) I added the following section to print exceptions in full format as well as logging every executed test:

    apply plugin: 'com.android.application'
    
    android { ... }
    
    dependencies { ...}
    
    tasks.withType(Test) {
        testLogging {
            exceptionFormat "full"
        }
        afterTest { desc, result ->
            println "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
        }
    }
    
    0 讨论(0)
提交回复
热议问题