Gradle: How to Display Test Results in the Console in Real Time?

后端 未结 16 1048
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 00:39

I would like to see test results ( system.out/err, log messages from components being tested ) as they run in the same console I run:

gradle test
         


        
16条回答
  •  难免孤独
    2020-11-28 01:34

    You can add a Groovy closure inside your build.gradle file that does the logging for you:

    test {
        afterTest { desc, result -> 
            logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
        }
    }
    

    On your console it then reads like this:

    :compileJava UP-TO-DATE
    :compileGroovy
    :processResources
    :classes
    :jar
    :assemble
    :compileTestJava
    :compileTestGroovy
    :processTestResources
    :testClasses
    :test
    Executing test maturesShouldBeCharged11DollarsForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
    Executing test studentsShouldBeCharged8DollarsForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
    Executing test seniorsShouldBeCharged6DollarsForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
    Executing test childrenShouldBeCharged5DollarsAnd50CentForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
    :check
    :build
    

    Since version 1.1 Gradle supports much more options to log test output. With those options at hand you can achieve a similar output with the following configuration:

    test {
        testLogging {
            events "passed", "skipped", "failed"
        }
    }
    

提交回复
热议问题