I am using Espresso 2.1 with ActivityTestRule, and I am looking for a way to set some static flags before onCreate()
in my application will be called.
I have some init code that I don't want called during instrumentation tests.
I am using Espresso 2.1 with ActivityTestRule, and I am looking for a way to set some static flags before onCreate()
in my application will be called.
I have some init code that I don't want called during instrumentation tests.
Application
onCreate()
is called after InstrumentationonCreate()
. For this case you need to implement a custom test runner which will subclass AndroidJUnitRunner and will override the callApplicationOnCreate() with your custom setup.Make sure to update your defaultConfig in the build.gradle to use new testInstrumentationRunner like this:
If you are looking to run some code before Activity
onCreate()
, subclass ActivityTestRule with your own implementation ofbeforeActivityLaunched()