How to show multiline assert messages with Android gradlew in commandline?

Viewed 67

I created a new Empty Activity Android project with Android Studio. I added an extra line to the useAppContext() test in ExampleInstrumentedTest class that shows a multiline assert message:

@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("com.example.myapplication", appContext.getPackageName());
        
        Assert.fail("1. Test failed\n2. Test failed\n3. Test failed\n");
    }
}

If I run the test in Android Studio I will get the proper assert message:

java.lang.AssertionError: 1. Test failed
2. Test failed
3. Test failed

But if I run it from Command Line I will get just two lines of the message:

$ ./gradlew connectedDebugAndroidTest
com.example.myapplication.ExampleInstrumentedTest > useAppContext[SM-G950U - 9] FAILED
        java.lang.AssertionError: 1. Test failed
        2. Test failed

> Task :app:connectedDebugAndroidTest FAILED

Platform/Versions/dependecies:

MacOS 11.3.1
Android Studio 4.2.1
classpath "com.android.tools.build:gradle:4.2.1"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

How can I show all lines in the Command Line?

0 Answers
Related