Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn on console output in Android Unit tests?

Is there any way to turn on the test logging in the console output?

I know that we can look at the test results generated in a HTML file and check standard output there, but I find it a little bit inconvinient.

I know that there is a way to do this with standard java plugin:

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

But using it in an Android project causes an error:

Could not find method test() 

Applying java plugin is unacceptable, of course, as it's not compatible with Android plugins.

like image 494
scana Avatar asked Mar 03 '15 12:03

scana


People also ask

How do I run a Gradle test in terminal?

Use the command ./gradlew test to run all tests.

How do I run all Gradle tests?

Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.

Where does Gradle store test results?

By default, gradle test displays only the test summary. P.S Gradle test generates the detailed tests' result at the build/reports/tests/test/index. html page.


1 Answers

android {  ...    testOptions {         unitTests.all {         // All the usual Gradle options.             testLogging {                 events "passed", "skipped", "failed", "standardOut", "standardError"                 outputs.upToDateWhen {false}                 showStandardStreams = true             }         }     }  } 

In my case, I followed this document and added the testLogging option as above. This should printout the log for the unit tests written under src/test folder but not the src/androidTest one. At the moment of this answer, I was using Android Studio 2.0 preview and gradle 2.8. The commands were ./gradlew test and ./gradlew test --continuein which ran in iTerm 2.

like image 159
ninjahoahong Avatar answered Sep 23 '22 23:09

ninjahoahong