Is it possible to find out if an Android application runs as part of an instrumentation test

前端 未结 8 1123
孤独总比滥情好
孤独总比滥情好 2021-01-04 11:01

Is there a runtime check for an application to find out if it runs as part of an instrumentation test?

Background: Our application performs a database sync when star

8条回答
  •  走了就别回头了
    2021-01-04 11:24

    This work for me because no actual device is running

    public static boolean isUnitTest() {
        return Build.BRAND.startsWith(Build.UNKNOWN) && Build.DEVICE.startsWith(Build.UNKNOWN) && Build.DEVICE.startsWith(Build.UNKNOWN) && Build.PRODUCT.startsWith(Build.UNKNOWN);
    }
    

提交回复
热议问题