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

前端 未结 8 1201
孤独总比滥情好
孤独总比滥情好 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:28

    If you are using Robolectric, you can do something like this:

    public boolean isUnitTest() {
            String device = Build.DEVICE;
            String product = Build.PRODUCT;
            if (device == null) {
                device = "";
            }
    
            if (product == null) {
                product = "";
            }
            return device.equals("robolectric") && product.equals("robolectric");
        }
    

提交回复
热议问题