I am currently working on sending a project for espresso testing. I read a bunch of documents and follow the instructions to get started.
Everything works fine, however, when it comes to the test related to Intents, the result looks strange.
In most cases, the tests passed on my Mac, but in my Windows colleague (not all tests fail) with the java.lang.IllegalStateException: init() must be called prior to using this method error message java.lang.IllegalStateException: init() must be called prior to using this method .
Oddly enough, if we run the Debug test in Android Studio, the step-by-step code step will go through it.
here is the test code:
@RunWith(AndroidJUnit4.class) @LargeTest public class MainActivityTest { @Rule public IntentsTestRule<MainActivity> mRule = new IntentsTestRule<>(MainActivity.class, true, false); AccountManager accountManager; MainActivity activity; private void buildLoginStatus() throws AuthenticatorException { DanteApp app = (DanteApp) InstrumentationRegistry.getTargetContext().getApplicationContext(); accountManager = app.getDanteAppComponent().accountManager(); DoctorModel doctorModel = AccountMocker.mockDoctorModel(); accountManager.save(doctorModel.doctor); accountManager.setAccessToken(doctorModel.access_token, false); } @Before public void before() throws Exception { buildLoginStatus();
Test library version (almost all the dependencies are updated, and we use both physical devices and an emulator for testing):
- rule: 0.4.1
- runner: 0.4.1
- espresso- *: 2.2.1
- support- *: 23.1.0
Any idea deserves appreciation. Thanks!
source share