Android Tests - How to Add Espresso Logs

I use

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' 

for tests and wondered if there is a way to tell espresso to print a magazine with the test running and the test finished, so it will be easy to see the logarithm if something happens.

It will be great to combine with papertrail to check why tests fail, and where with private integration servers.

+6
source share
4 answers

You can record Android logs by running tests on your CI server through Spoon . Check out the examples on your website and see the links below, such as reports and then the logs for one of the tests. Each test run has records recorded and saved in the report.

Report: http://square.imtqy.com/spoon/sample/index.html

Log examples: http://square.imtqy.com/spoon/sample/logs/0403681E12013007/com.example.spoon.ordering.tests.OrderActivityTest/testMakeASandwich_ItTastesGood.html

+7
source

Next time, please show us what steps you took to make yourself work.

You can just look in logcat after running the tests. Some of the helper classes are already registered for logcat. For example, see android.support.test.internal.runner.lifecycle.ActivityLifecycleMonitorImpl . It registers activity life cycle states:

 D/LifecycleMonitor: Lifecycle status change: com.example.android.MyActivity@f3c7955 in: STOPPED 

Any log statements inside your test classes will also be displayed. Finally, any log statements inside your test classes will be displayed.

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

I can see the logs both in Android Studio and on the command line.

I conclude by saying that I can also make the log work if Timber is used instead.

+3
source

I checked the framework code and it seems to use System.out.println, which also works in tests. Android magazine sadly does not.

+2
source

I know it has been a long time since you wrote this comment ... but how did you add logcat to your espresso report? Thank you in advance!

0
source

All Articles