vendredi 23 mars 2018

Espresso Test Output Truncated in Console, How to Get Full Results?

When outputting test failures with multiple lines, I've found that Gradle and the Android Plugin truncate results. For example, if an exception message has 12 lines, only 3 will display in the console. The other 12 lines, along with the stack trace, end up in the generated HTML and XML results files, but I wanted to be able to put this output in the console as well.

Here's what displays in the console:

com.company.espressoTests.tests.FailTest > thisTestWillFail[Pixel 2 - 8.1.0] FAILED 
    java.lang.Throwable: class java.lang.AssertionError
    Whoops, true != false

And here's what displays in Android Studio, the generated HTML results file, and the generated XML results file:

java.lang.Throwable: class java.lang.AssertionError
Whoops, true != false
Failed as it should

thisTestWillFail FAILED!
Steps to reproduce:
    1. Setup Complete, starting test.
    2. This is an action
    3. This is a second action
    4. More actions!
    5. Test finished.
End Actions.
(Followed by a full stack trace)

I've tried using --info, --debug, and --stacktrace, none of that produced results. I also modified the test options for unit tests, asking for full stacktrace output, even asking for System.out and System.err output from the tests to display on the console. None of these options changed the output of the test failure.

I believe this has to do more with the Android Plugin than Gradle, because, with our Appium tests, we were able to do this output without issue.

We're using a test rule to catch exceptions (t in the below example) from test failures, and adding some output to it like so:

 Throwable newError = new Throwable(t.getClass() + "\n"
                        + t.getMessage() + "\n\n"
                        + method.getName() + " FAILED!\n"
                        + "Steps to reproduce:\n"
                        + ActionLog.instance().getActions());
                newError.setStackTrace(t.getStackTrace());

The Android Gradle plugin documentation for Espresso test options is, unfortunately, lacking. Does anyone know why this could be truncated, and how I could get this information to print on the console? Thanks!

Aucun commentaire:

Enregistrer un commentaire