20

As I upload a new version of my app to Google Play I get a Pre-Launch testing report that's pretty nice and fine, but the issue is that most of the time the AI just wanders around the setup and does not test the actual UI. I'd like to pre-complete the setup quickly and randomly for those devices.

So my question is, is there a way to detect that it's running on those test devices?

Avamander
  • 497
  • 16
  • 31

2 Answers2

21

You can detect a pre-launch test device with the following:

private boolean isTestDevice() {  
  String testLabSetting = Settings.System.getString(getContentResolver(), "firebase.test.lab");
  return "true".equals(testLabSetting);
}

See: https://firebase.google.com/docs/test-lab/android/android-studio#modify_instrumented_test_behavior_for

Ryan R
  • 8,342
  • 15
  • 84
  • 111
  • Is Firebase's test lab exactly like Google Pre-Launch report? – Avamander Jul 13 '17 at 13:49
  • Pretty sure but haven't tested it myself. I will be testing this code in production shortly. I'll report back... – Ryan R Jul 13 '17 at 21:30
  • 7
    I tested this and it detects the test device. – Ryan R Jul 14 '17 at 15:38
  • 2
    It definitely works, although, I have found out that Firebase Analytics will still record the ```first_open```, ```screen_view``` and ```session_start``` events. From there on, the tests will stop working. Would there be any way of preventing this from happening? It's making my Firebase reports 'dirty'. – xarlymg89 Jun 20 '19 at 15:39
  • @xarlymg89 did you find a solution to avoid first_open and etc under test runs? – serein Sep 18 '19 at 19:23
  • @serein sadly not. I was testing other analytics tools, like the one from Microsoft. But haven't invested much more time in this matter. Lately I'm not sending too many APKs to the Play Console, so it's not a priority for me. But it'll certainly be great to fix this, in my opinion, misbehaviour. – xarlymg89 Sep 19 '19 at 07:40
3

In case anyone gets here looking for how to do this with React Native, check out the react-native-firebase package utils().isRunningInTestLab: https://rnfirebase.io/app/utils#test-lab.

user161107
  • 401
  • 3
  • 6