3
버튼이 포함 된 간단한 활동이 있습니다. 버튼을 누르면 두 번째 활동이 실행됩니다. 이제 안드로이드 계측 테스트가 처음입니다. 지금까지 내가Android 계측 실행 활동
public class TestSplashActivity extends
ActivityInstrumentationTestCase2<ActivitySplashScreen> {
private Button mLeftButton;
private ActivitySplashScreen activitySplashScreen;
private ActivityMonitor childMonitor = null;
public TestSplashActivity() {
super(ActivitySplashScreen.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
final ActivitySplashScreen a = getActivity();
assertNotNull(a);
activitySplashScreen=a;
mLeftButton=(Button) a.findViewById(R.id.btn1);
}
@SmallTest
public void testNameOfButton(){
assertEquals("Press Me", mLeftButton.getText().toString());
this.childMonitor = new ActivityMonitor(SecondActivity.class.getName(), null, true);
this.getInstrumentation().addMonitor(childMonitor);
activitySplashScreen.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mLeftButton.performClick();
}});
Activity childActivity=this.getInstrumentation().waitForMonitorWithTimeout(childMonitor, 5000);
assertEquals(childActivity, SecondActivity.class);
}
} 이제
I 버튼 작동의 텍스트를 얻을 첫 번째 어설 쓴 것입니다. 내가 수행 클릭을 호출 할 때, 나는 지금은 지금은 계측 테스트의 관점에서, 안드로이드 응용 프로그램의 맥락에서이 예외를 이해 예외를
Only the original thread that created a view hierarchy can touch its views.
를 얻을. 어떻게하면 버튼에 대한 클릭 이벤트를 수행 할 수 있으며 두 번째 활동이로드되었는지 확인할 수 있습니다.
은 버튼을 클릭하면 새로운 활동을 시작합니다. 두 번째 활동이 시작되거나 시작될 때 버튼을 클릭 한 후이 시나리오를 테스트하고 싶습니다. 이 시나리오를 어떻게 테스트 할 수 있습니까? – user1730789
내가 편집 한 부분 코드입니다. – user1730789
나는 본다. 그런 클릭을 보내지 마십시오. 계측 클래스를 사용하여 클릭을 보내야합니다. 내 게시물을 편집했습니다. –