Android测试 - 如何添加Espresso日志

Dan*_*ico 6 continuous-integration android android-espresso

我正在使用

androidTestCompile 'com.android.support.test:runner:0.3'
    androidTestCompile 'com.android.support.test:rules:0.3'
    androidTestCompile 'com.android.support:support-annotations:23.0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
        // this library uses the newest app compat v22 but the espresso contrib still v21.
        // you have to specifically exclude the older versions of the contrib library or
        // there will be some conflicts
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile 'junit:junit:4.12'
Run Code Online (Sandbox Code Playgroud)

对于测试,并想知道是否有办法说espresso打印日志与开始测试和完成测试所以将很容易看到logcat如果发生的事情.

与papertrail混合以检查测试失败的原因以及私有集成服务器的位置将非常棒.

Sam*_*rds 7

您可以通过Spoon在CI服务器上运行测试来捕获Android日志.请参阅其网站上的操作示例,并查看以下链接,例如报告,然后查看其中一个测试的日志.每次测试运行都会捕获日志并将其保存在报告中.

报告输出:http://square.github.io/spoon/sample/index.html

示例日志:http://square.github.io/spoon/sample/logs/0403681E12013007/com.example.spoon.ordering.tests.OrderActivityTest/testMakeASandwich_ItTastesGood.html


tir*_*r38 3

下次请向我们展示您自己采取了哪些步骤来实现此目的。

您可以在运行测试后查看 logcat。一些帮助程序类已经记录到 logcat。例如看看 android.support.test.internal.runner.lifecycle.ActivityLifecycleMonitorImpl. 它记录活动生命周期状态:

D/LifecycleMonitor: Lifecycle status change:com.example.android.MyActivity@f3c7955 in: STOPPED
Run Code Online (Sandbox Code Playgroud)

被测试的类中的任何日志语句也将显示。最后,测试类中的所有日志语句都会显示出来。

@RunWith(AndroidJUnit4.class)
public class SomeTest {

    @Before
    public void setUp() throws Exception {
        Log.d(TAG, "setup");
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

我可以在 Android Studio 和命令行中查看日志。

最后我要说的是,如果使用 Timber,我也能够让日志记录正常工作。