2016-04-28 14 views
21

Come spiegato in altri thread Gradle può essere configurato per accedere risultati dei test nella consolle:Gradle: come visualizzare i risultati di AndroidTest nella console?

Fondamentalmente, questo può essere impostato attraverso la seguente operazione :

tasks.withType(Test) { 
    testLogging { 
     // Custom configuration 
    } 
} 

Questo funziona bene per i test unitari e si presenta un po 'come questo:

... 
:app:assembleDebugUnitTest 
:app:testDebugUnitTest 
:app:processDebugResources 

com.example.StringsTest > formatValue PASSED 
com.example.StringsTest > formatValueWithDecimals FAILED 

1 test completed, 1 failed 

Inoltre, unit test ho anche eseguito test di integrazione utilizzando il seguente comando:

$ ./gradlew connectedAndroidTest 

Quando guardo in uscita nella console sono manca il test individuale come scritto per i test unitari. Come posso configurare la registrazione dei test per i test di strumentazione?

+0

Hai qualche fortuna con questo JJD? –

+0

Non ancora. Per essere onesti ho dovuto ritardare questi test per un po '. Lo riprenderò appena le cose torneranno alla normalità. Hai provato l'approccio di Hidro? – JJD

+0

Nah, volevo solo un approccio basato su Gradle. Speravo qualcosa come 'tasks.withTest'. –

risposta

8

Collegato prova l'output del registro e gli eventi a logcat, poiché viene eseguito su un dispositivo/emulatore. Gli eventi di prova sono registrati sotto il tag TestRunner.

Io uso il seguente script per avviare adb logcat sullo sfondo, che registra gli eventi TestRunner mentre i test sono in esecuzione e quindi elimina il processo logcat in seguito.

adb logcat *:S TestRunner:V & LOGCAT_PID=$! ; \ 
./gradlew :app:cAT ; \ 
if [ -n "$LOGCAT_PID" ] ; then kill $LOGCAT_PID; fi 

che produce qualcosa di simile:

[1] 90439 
--------- beginning of system 
--------- beginning of main 
:app:preBuild UP-TO-DATE 
:app:preDebugBuild UP-TO-DATE 
... 
:app:packageDebugAndroidTest UP-TO-DATE 
:app:assembleDebugAndroidTest UP-TO-DATE 
> Building 96% > :app:connectedDebugAndroidTest06-13 09:25:04.259 5460 5474 I TestRunner: run started: 23 tests 
06-13 09:25:04.267 5460 5474 I TestRunner: started: testHomeClick(io.github.hidroh.tldroid.CommandActivityTest) 
06-13 09:25:06.899 5460 5474 I TestRunner: finished: testHomeClick(io.github.hidroh.tldroid.CommandActivityTest) 
06-13 09:25:06.903 5460 5474 I TestRunner: started: testRenderNoContent(io.github.hidroh.tldroid.CommandActivityTest) 
06-13 09:25:08.128 5460 5474 I TestRunner: finished: testRenderNoContent(io.github.hidroh.tldroid.CommandActivityTest) 
06-13 09:25:08.130 5460 5474 I TestRunner: started: testStateRestoration(io.github.hidroh.tldroid.CommandActivityTest) 
06-13 09:25:09.547 5460 5474 I TestRunner: finished: testStateRestoration(io.github.hidroh.tldroid.CommandActivityTest) 
... 
06-13 09:25:35.283 5460 5474 I TestRunner: run finished: 23 tests, 0 failed, 0 ignored 
:app:connectedDebugAndroidTest 
:app:createDebugAndroidTestCoverageReport 
:app:connectedAndroidTest 

BUILD SUCCESSFUL 

Total time: 1 mins 7.485 secs 
[1]+ Terminated: 15   adb logcat *:S TestRunner:V 

Potrà comando naturalmente Tweak logcat utilizzare un registratore di vostra scelta, per esempio un registratore di colori, o modifica logcat filterspec per mostrare più eventi.

+0

Funziona perfettamente! Anche se non è un "approccio basato sul gradiente" – gorbysbm

2

La versione semplice è solo da usare:

./gradlew connectedAndroidTest --info

ci vuole un littlebit per accedere nella finestra di terminale/console, ma sta mostrando tutto bello , colorata e formattata

come ...

…ShowsIntroduction[SM-G950F - 7.0] SUCCESS 
…BackButtonReturnsToOnboardingScreen[SM-G950F - 7.0] SKIPPED 

buona fortuna & & divertirsi

Problemi correlati