How to detect whether android app is running UI test with Espresso

后端 未结 8 1936
-上瘾入骨i
-上瘾入骨i 2020-12-03 06:56

I am writing some Espresso tests for Android. I am running in the the following problem:

In order for a certain test case to run properly, I need to disable some fea

8条回答
  •  渐次进展
    2020-12-03 07:40

    How about a flag in BuildConfig class?

    android {
        defaultConfig {
            // No automatic import :(
            buildConfigField "java.util.concurrent.atomic.AtomicBoolean", "IS_TESTING", "new java.util.concurrent.atomic.AtomicBoolean(false)"
        }
    }
    

    Add this somewhere in your test classes.

    static {
        BuildConfig.IS_TESTING.set(true);
    }
    

提交回复
热议问题