微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在命令行中使用 Android gradlew 显示多行断言消息?

如何解决如何在命令行中使用 Android gradlew 显示多行断言消息?

我使用 Android Studio 创建了一个新的 Empty Activity Android 项目。我在 useAppContext() 类中的 ExampleInstrumentedTest 测试中添加了额外的一行,以显示多行断言消息:

@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");
    }
}

如果我在 Android Studio 中运行测试,我会得到正确的断言消息:

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

但是如果我从命令行运行它,我只会得到两行消息:

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

> Task :app:connectedDebugAndroidTest Failed

平台/版本/依赖项:

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'

如何在命令行中显示所有行?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。