लौटाती है मेरे पास एक टेस्ट केस है जो इंस्ट्रूमेंटेशन का उपयोग करता है। सक्रियता मॉनिटर यह जांचने के लिए कि कोई इरादा भेजा गया था या नहीं। जब परीक्षण सफल होता है तो यह ठीक काम करता है। अगर दावा विफल रहता है, तो अगला टेस्ट केस setUp() में getActivity() कॉल पर लटकता है।एंड्रॉइड गतिविधि मॉनिटर विफलता कारण प्राप्त करती है सक्रियता() कभी भी
क्या मुझे साफ करने के लिए कुछ विधि कॉल करना है?
ऐसा लगता है कि यह एक गतिविधि लॉन्चिंग के आसपास घूमता है, लेकिन गतिविधि मॉनिटर इसे पकड़ नहीं रहा है। यही है, IntentFilter ट्रिगर नहीं किया गया था। परीक्षण विफल रहता है लेकिन नई गतिविधि कभी खारिज नहीं होती है और अगली getActivity() कॉल में हस्तक्षेप करती है।
यह समस्या similar to another question है, लेकिन यह समाधान वहां (super.tearDown() को कॉल करने से मेरी समस्या ठीक नहीं हुई।
public class SimpleActivityTest
extends ActivityInstrumentationTestCase2<SimpleActivity> {
private SimpleActivity activity;
@Override
protected void setUp() throws Exception {
super.setUp();
this.getInstrumentation().setInTouchMode(false);
Intent intent = new Intent();
intent.putExtra("DATA_ITEM_1", 1);
intent.putExtra("DATA_ITEM_2", 2);
this.setActivityIntent(intent);
this.activity = getActivity(); // this call hangs on second test
}
public void testOtherActivityCalled() {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_VIEW);
ifilter.addDataScheme("http");
ifilter.addDataAuthority("some.domain.com", null);
ifilter.addDataPath("foobar", PatternMatcher.PATTERN_PREFIX);
ActivityMonitor activityMonitor = getInstrumentation().addMonitor(
ifilter, null, false);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// launch other activity somehow
}
});
getInstrumentation().waitForIdleSync();
Activity otherActivity = activityMonitor.waitForActivityWithTimeout(2000);
assertNotNull(otherActivity);
otherActivity.finish();
}
public void testSomethingElse() {
// This code will never run because getActivity() in setUp() will
// never return
}
}
क्या आपने इस समस्या को हल किया? मेरे पास वही है, और यह नहीं पता कि इसे कैसे ठीक किया जाए :( – dexxtr