Debugging Network Calls in Android Espresso Tests

Ronell Lukasik
2 min readDec 19, 2022

When writing our Android Espresso tests, we needed a way to monitor the network calls to see which calls were getting stubbed correctly, which calls had something stubbed incorrect, or which calls were missed. We use Charles Proxy for iOS which works great, but the setup for the Android Emulators wasn’t so easy and unfortunately, most of the time, we weren’t able to get it working.

However, Android Studio has a built-in feature that you can use. Let me introduce you to App Inspection.

Add breakpoints in Android Studio to one of your tests, then Debug your test. When it hits the first breakpoint, select App Inspection and select you app process that is running on the emulator in the upper left corner (of first screenshot).

As Network Activity occurs within the app, you will now see it appear as spikes within this section:

You can press Play on the Debug tab to continue to your next breakpoint to have network activity occur. Go back to the App Inspection tab and select the section that contains spikes to see the calls that occurred.

Here you can select the network call and see the requests & responses that were generated.

You aren’t able to intercept the calls like you can in Charles Proxy though to block/allow specific calls, or rewrite the response codes or response payloads. So a tool like Charles Proxy does allow you to do a lot more; however this is an easy approach to see the networking calls being made and the request/responses being made.

--

--