Android Pro Tip: How to determine if you’re running in a Firebase Test Lab

Image for post
Image for post

In this entry of my Android Pro Tip’s series I’m going to fill you in on an easy, one line piece of code you can use to detect if you’re running in a Firebase Test Lab.

Why would you want to do this?

There are a number of reasons you might need to detect if you’re running inside a Firebase Test Lab, a few of them being:

  • You might want your app to react a little differently than it would when being run by a real users.
  • You might want to disable analytics in test lab so as not to dilute your analytical data.
  • You might want to disable access to certain features that cost you money such as uploading to image buckets or running certain backend requests.
  • You might want to add a “test” header to certain backend requests so you can differentiate real data from test lab data.

You get the idea.

So how do you do it?

fun isInTestLab(contentResolver: ContentResolver): Boolean {
return Settings.System.getString(contentResolver,
"firebase.test.lab") == "true"
}

Easy right? Firebase Test Lab returns true when querying for this system settings string, so you can now detect when you’re running inside the test lab inside your code & react accordingly. Simple.

If you have any thoughts or feedback, I’d love to hear what you think in the comments! Also if you have any requests for little hacks or tip’s like this you might be interested let me know & I’ll see what I can do!

I’d love to hear what you think!

Written by

Freelance Android Developer since 2012 🎙️Host of CoffeeAndCodingPod.com 🌍 World Tourist ☕ Coffee Addict | robj.me

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store