मैं वर्तमान में एस्प्रेसो परीक्षण में एक प्रोजेक्ट को दबाकर काम कर रहा हूं। मैंने दस्तावेजों का एक समूह पढ़ा है और शुरू करने के लिए दिए गए अभ्यासों का पालन किया है।एंड्रॉइड एस्प्रेसो इंटेंट्स परीक्षण '`init() के साथ यादृच्छिक रूप से विफल होने के लिए इस विधि का उपयोग करने से पहले कहा जाना चाहिए'
सबकुछ ठीक काम करता है, हालांकि, जब यह इरादे से संबंधित परीक्षण की बात आती है, तो परिणाम अजीब होता है।
अधिकांश समय, मेरे मैक में पारित परीक्षण, लेकिन असफल संदेश java.lang.IllegalStateException: init() must be called prior to using this method
के साथ मेरे सहयोगी के विंडोज़ (सभी परीक्षण विफल नहीं) में विफल हो गए।
काफी अजीब बात है, अगर हम एंड्रॉइड स्टूडियो में डीबग परीक्षण चलाते हैं तो चरण-दर-चरण कोड प्रवाह होता है, यह गुजरता है।
@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();
// must login
assertThat(accountManager.hasAuthenticated(), is(true));
activity = mRule.launchActivity(null);
// block all of the outer intents
intending(not(isInternal())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));
}
@After public void tearDown() throws Exception {
accountManager.delete();
}
// failed
@Test public void testViewDisplay() throws Exception {
// check tabhost is displayed
onView(withClassName(equalTo(TabHost.class.getName()))).check(matches(isDisplayed()));
// check toolbar is displayed
onView(withClassName(equalTo(ToolBar.class.getName()))).check(matches(isDisplayed()));
}
// passed
@Test public void testCallServiceHotline() throws Exception {
// switch to the account tab layout
onView(withChild(withText(R.string.account))).perform(click());
// click account menu to make a service call
onView(withId(R.id.contact)).perform(click());
// check call start expectly
intended(allOf(
not(isInternal()),
hasAction(Intent.ACTION_DIAL),
hasData(Uri.parse("tel:" + activity.getString(R.string.call_service)))
));
}
// failed
@Test public void testOpenSettingsUI() throws Exception {
// stub all internal intents
Intents.intending(isInternal())
.respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));
onView(withChild(withText(R.string.account))).perform(click());
onView(withId(R.id.setting)).perform(click());
// check open settings activity successfully
intended(anyOf(
hasComponent(SettingActivity.class.getName())
));
}
}
परीक्षण पुस्तकालय संस्करण (लगभग सभी निर्भरता तारीख तक कर रहे हैं और हम परीक्षण करने के लिए दोनों भौतिक विज्ञान उपकरणों और एमुलेटर का उपयोग करें):
- नियम: 0.4
यहाँ परीक्षण कोड है .1
- धावक: 0.4.1
- espresso- *: 2.2.1
- समर्थन *: 23.1.0
कोई भी विचार प्रशंसा के योग्य है। धन्यवाद!