7

에스프레소 테스트 프로젝트를 사용하여 다음 UI 테스트를 자동화해야합니다.에스프레소 카메라 조작 UI 테스트

작동 :

내 휴대 전화 카메라를 연 버튼을 클릭하십시오. 이미지 캡처 및 sdcard 저장 공간에 이미지 저장. 완료되면 화면의 작은 이미지보기를 업데이트하십시오.

응용 프로그램이 정상적으로 작동하지만 위의 다른 모든 작업과 유사한 유형의 작업은 수작업으로 수동으로 테스트하는 데 시간이 오래 걸립니다.

+0

아래에서 가능한 최선의 해결책을 발견했다. 카메라 앱을 인스트루먼트 할 수 없습니다. 대신 UI 자동화 도구를 사용해보십시오. http://developer.android.com/tools/testing/testing_ui.html – haffax

답변

2

여전히 필요한 경우이 흐름을 테스트하는 데 사용할 수있는 활동 결과를 조롱하는 새 Espresso-Intent를 사용할 수 있습니다. See the sample from Android Testing

+2

바로 수정되었으므로 올바른 링크는 https://github.com/googlesamples/android-testing/tree/master/입니다. ui/espresso/IntentsBasicSample – Thalescm

+0

@Thalescm 업데이트 해 주셔서 감사합니다! – Yenchi

6

나는 비슷한 문제 작업 당신은 응용 프로그램 내에서 활동을 테스트 할 수 있습니다 에스프레소와 링크 Camera UI test

// CameraActivityInstrumentationTest.java 
public class CameraActivityInstrumentationTest { 

    // IntentsTestRule is an extension of ActivityTestRule. IntentsTestRule sets up Espresso-Intents 
    // before each Test is executed to allow stubbing and validation of intents. 
    @Rule 
    public IntentsTestRule<CameraActivity> intentsRule = new IntentsTestRule<>(CameraActivity.class); 

    @Test 
    public void validateCameraScenario() { 
     // Create a bitmap we can use for our simulated camera image 
     Bitmap icon = BitmapFactory.decodeResource(
       InstrumentationRegistry.getTargetContext().getResources(), 
       R.mipmap.ic_launcher); 

     // Build a result to return from the Camera app 
     Intent resultData = new Intent(); 
     resultData.putExtra("data", icon); 
     Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData); 

     // Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond 
     // with the ActivityResult we just created 
     intending(toPackage("com.android.camera2")).respondWith(result); 

     // Now that we have the stub in place, click on the button in our app that launches into the Camera 
     onView(withId(R.id.btnTakePicture)).perform(click()); 

     // We can also validate that an intent resolving to the "camera" activity has been sent out by our app 
     intended(toPackage("com.android.camera2")); 

     // ... additional test steps and validation ... 
    } 
} 
+0

일부 장치 (예 : SAMSUNG Galaxy S8)에는 "com.sec.android.app.camera"패키지 이름의 카메라 앱이 있습니다. 이 해결책은 그 장치에서 작동하지 않습니까? –

관련 문제