Gradle: ¿Cómo mostrar los Resultados de las Pruebas en la Consola en tiempo Real?
Me gustaría ver los resultados de las pruebas ( sistema.out / err, registra los mensajes de los componentes que se están probando) mientras se ejecutan en la misma consola que corro:
gradle test
Y no esperar hasta que se hagan las pruebas para ver los informes de prueba (que solo se generan cuando se completan las pruebas, por lo que no puedo "tail-f" nada mientras se ejecutan las pruebas)
11 answers
Puedes ejecutar Gradle con nivel de registro de INFORMACIÓN en la línea de comandos. Te mostrará el resultado de cada prueba mientras se están ejecutando. La desventaja es que obtendrá mucho más salida para otras tareas también.
gradle test -i
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-19 14:01:17
Puede agregar un cierre Groovy dentro de su compilación.archivo de gradle que realiza el registro por usted:
test {
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}
En tu consola se lee así:
: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
Desde la versión 1.1 Gradle soporta muchas más opciones para registrar la salida de prueba. Con esas opciones a mano se puede lograr una salida similar con la siguiente configuración:
test {
testLogging {
events "passed", "skipped", "failed"
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-10 12:28:25
Aquí está mi versión elegante:
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
tasks.withType(Test) {
testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true
// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-23 10:19:08
Como stefanglase respondió:
Agregar el siguiente código a su build.gradle
(desde la versión 1.1) funciona bien para la salida en pasado, saltó y falló las pruebas.
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
Lo que quiero decir adicionalmente (descubrí que esto es un problema para empezar) es que el comando gradle test
ejecuta la prueba solo una vez por cambio.
Así que si lo está ejecutando la segunda vez no habrá salida en los resultados de la prueba. Puedes también puedes ver esto en la salida del edificio: gradle dice UP-TO-DATE en las pruebas. Así que no se ejecuta una n-ésima vez.
¡Smart gradle!
Si desea forzar la ejecución de los casos de prueba, utilice gradle cleanTest test
.
Esto está un poco fuera de tema, pero espero que ayude a algunos novatos.
Editar
Como sparc_spread se indica en los comentarios:
Si quieres forzar a gradle a siempre ejecutar pruebas nuevas (lo que puede no ser siempre una buena idea) puedes añadir outputs.upToDateWhen {false}
a testLogging { [...] }
. Sigue leyendo aquí .
Paz.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-24 11:00:22
Agregue esto a build.gradle
para evitar que gradle ingiera stdout y stderr.
test {
testLogging.showStandardStreams = true
}
Está documentado aquí.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-24 11:00:03
Descargo de responsabilidad: Soy el desarrollador del plugin Gradle Test Logger.
Puedes usar el complemento Gradle Test Logger para imprimir hermosos registros en la consola. El plugin ofrece una serie de temas y opciones de configuración para adaptarse a una gran audiencia.
Nota: El plugin Gradle Test Logger v1.4+ ahora también admite la ejecución de pruebas paralelas. Simplemente use un tema adecuado.
Ejemplos
Uso
plugins {
id 'com.adarshr.test-logger' version '<version>'
}
Asegúrate de obtener siempre la última versión de de Gradle Central.
Configuración
No necesita ninguna configuración en absoluto. Sin embargo, el plugin ofrece algunas opciones. Esto se puede hacer de la siguiente manera (se muestran los valores predeterminados):
testlogger {
// pick a theme - mocha, standard, plain, mocha-parallel, standard-parallel or plain-parallel
theme 'standard'
// set to false to disable detailed failure logs
showExceptions true
// set threshold in milliseconds to highlight slow tests
slowThreshold 1000
// displays a breakdown of passes, failures and skips along with total duration
showSummary true
// set to false to hide passed tests
showPassed true
// set to false to hide skipped tests
showSkipped true
// set to false to hide failed tests
showFailed true
// enable to see standard out and error streams inline with the test results
showStandardStreams false
// set to false to hide passed standard out and error streams
showPassedStandardStreams true
// set to false to hide skipped standard out and error streams
showSkippedStandardStreams true
// set to false to hide failed standard out and error streams
showFailedStandardStreams true
}
Espero que disfrutes usarlo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-17 08:02:00
La tarea' test ' no funciona para el plugin de Android, para el plugin de Android usa lo siguiente:
// Test Logging
tasks.withType(Test) {
testLogging {
events "started", "passed", "skipped", "failed"
}
}
Véase lo siguiente: https://stackoverflow.com/a/31665341/3521637
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 10:31:36
Como continuación de La gran respuesta de Shubham Me gusta sugerir el uso de enum valores en lugar de cadenas. Por favor, eche un vistazo a la documentación de la clase TestLogging.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
tasks.withType(Test) {
testLogging {
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showCauses true
showExceptions true
showStackTraces true
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:43
En Gradle usando el plugin de Android:
gradle.projectsEvaluated {
tasks.withType(Test) { task ->
task.afterTest { desc, result ->
println "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}
}
Entonces la salida será:
Ejecutando test testConversionMinutes [org.ejemplo.app.prueba.DurationTest] con resultado: SUCCESS
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-24 10:58:48
Mi versión minimalista favorita basada en la respuesta de Shubham Chaudhary.
Pon esto en build.gradle
archivo:
test {
afterSuite { desc, result ->
if (!desc.parent)
println("${result.resultType} " +
"(${result.testCount} tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped)")
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-31 15:16:19
Combinación de La gran respuesta de Shubham y JJD usa enum en lugar de string
tasks.withType(Test) {
testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.PASSED,
TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT
showExceptions true
exceptionFormat TestExceptionFormat.FULL
showCauses true
showStackTraces true
// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR
exceptionFormat TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:18:23