2016-07-20 2 views
-2

testAYLogout()을 인스턴스화하고 응용 프로그램을 실행하려고하면 testAXEndTrip()도 실행됩니다. 왜 그런가요? 당신은 Testing Support Library를 사용해야합니다uiautomator에서 상속을 사용할 수 있습니까? 그렇다면 어떻게?

public class ApplicationTest extends UiAutomatorTestCase { 

    public void testAYLogout() throws RemoteException, UiObjectNotFoundException { 
     //Get the device state 
     UiDevice myDevice = getUiDevice(); 
     //menu button 
     UiObject menuButton = new UiObject(new UiSelector().className(android.widget.ImageButton.class.getName()).index(0)); 
     //logout button 
     UiObject logoutButton = new UiObject(new UiSelector().className(android.widget.CheckedTextView.class.getName()).text("Logout")); 
     //yes button 
     UiObject yesButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("Yes")); 
     //no button 
     UiObject noButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("No")); 
     UiObject loginText = new UiObject(new UiSelector().className(android.widget.TextView.class.getName()).text("Login")); 

     if (!myDevice.isScreenOn()) { 
      myDevice.wakeUp(); 
     } 

     //click menu button and wait for new window 
     menuButton.clickAndWaitForNewWindow(); 
     assertTrue(logoutButton.exists()); 
     //click logout 
     logoutButton.clickAndWaitForNewWindow(); 
     //click no 
     noButton.clickAndWaitForNewWindow(); 
     menuButton.clickAndWaitForNewWindow(); 
     logoutButton.clickAndWaitForNewWindow(); 
     //click yes button 
     yesButton.clickAndWaitForNewWindow(); 
     assertTrue(loginText.exists()); 

    } 

public void testAXEndTrip() throws RemoteException, UiObjectNotFoundException { 


     //get device 
     UiDevice myDevice = getUiDevice(); 
     //pick up location feild 
     UiObject okButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("Ok").index(0)); 
     //end trip button 
     UiObject endTripButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("END TRIP").index(1)); 
     //no button 
     UiObject noButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("No")); 
     //yes button 
     UiObject yesButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("Yes")); 
     //submit button 
     UiObject submitButton = new UiObject(new UiSelector().className(android.widget.Button.class.getName()).text("Submit")); 
     //rate button 
     UiObject rateButton = new UiObject(new UiSelector().className(android.widget.ImageButton.class.getName()).index(4)); 
     //feedback field 
     UiObject feedback = new UiObject(new UiSelector().className(android.widget.EditText.class.getName()).index(1)); 
     //map 
     UiObject map = new UiObject(new UiSelector().className(android.view.View.class.getName()).index(0)); 

     //wake up device if screen is off 
     if (!myDevice.isScreenOn()) 
      myDevice.wakeUp(); 

     rateButton.waitForExists(5000); 
     rateButton.clickAndWaitForNewWindow(); 
     feedback.setText("ride or die ma niguh"); 
     submitButton.clickAndWaitForNewWindow(); 
     assertTrue(map.exists()); 

    } 

} 

다음이 내 메인 클래스

public class MainTest extends ApplicationTest{ 

    public static void TestMain() throws RemoteException, UiObjectNotFoundException { 
     MainTest login = new MainTest(); 
     login.testAYLogout(); 

    } 
} 

답변

-1

입니다.

먼저

dependencies { 
    ... 
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' 
} 

그런 다음 Gradle을 파일에 uiautomator 종속성을 추가, 테스트를 실행, 마지막으로이 일

@RunWith(AndroidJUnit4.class) 
@SdkSuppress(minSdkVersion = 18) 
public class MySampleTest extends MyAbstractTest { 
    ... 

    @Test 
    public void myTest() { 
     ... 
    } 

} 

같은 테스트 케이스 클래스를 만들 수 있습니다. 프로젝트에서 기본 계측 주자로 AndroidJUnitRunner을 지정해야합니다.

android { 
    defaultConfig { 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
} 
+0

나는 이미 선생님과 내 응용 프로그램이 실행 중이며 문제가 없습니다. 안드로이드가 java이기 때문에 상속을 사용할 수 있습니까? –

+0

물론 가능합니다. 그것을 보여주기 위해 편집 됨. –

+0

내가 도움 녀석에게 어디서 잘못했는지 알아 냈습니다. –

관련 문제