-1
我發生了一個煩人的問題,儀器測試類之一顯示在灰色,當我開始所有測試(包androidTest)這一個被省略(其他人開始就好了)。任何想法可能是什麼原因呢?所有睾丸開始時省略灰色儀器測試
@RunWith(AndroidJUnit4.class)
public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
@Rule
public ActivityTestRule<LoginActivity> mActivityRule =
new ActivityTestRule<>(LoginActivity.class, true, false);
private MockWebServer server;
private LoginActivity loginActivity;
private SharedPreferences loginDetails;
public LoginActivityTest() {
super(LoginActivity.class);
}
Instrumentation.ActivityMonitor giftListActivityMonitor;
@Before
public void setUp() throws Exception {
super.setUp();
// Create a MockWebServer. These are lean enough that you can create a new
// instance for every unit test.
server = new MockWebServer();
// Start the server.
server.start();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
loginDetails = getInstrumentation().getTargetContext().getSharedPreferences("login_details",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = loginDetails.edit();
editor.clear();
editor.commit();
KupMiConstans.BASE_URL = server.url("/").toString();
loginActivity = this.getActivity();
Instrumentation instrumentation = getInstrumentation();
giftListActivityMonitor = instrumentation.addMonitor(GiftListActivity.class.getName(), null, false);
new PrepareSingletons(getInstrumentation().getContext());
}
@Test
...
@Test
...
@After
public void tearDown() throws Exception {
SharedPreferences loginDetails = getInstrumentation().getTargetContext().getSharedPreferences("login_details",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = loginDetails.edit();
editor.clear();
editor.commit();
try {
server.shutdown();
} catch (Exception e) {
}
}
在此先感謝!