2016-07-19 57 views
-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) { 
    } 
} 

在此先感謝!

Test displayed on grey

回答

0

這很愚蠢。

灰色圖標被顯示,因爲類中的第一件事必須是默認構造函數。在第一次測試完全基於意式濃縮咖啡並且至少需要一個斷言*之前,類在測試中被省略。奇怪的是,訂單非常重要...