7

Espresso test projesi ile aşağıdaki işlem için UI testlerimi otomatik hale getirmem gerekiyor.Kamera Çalışması Espresso ile UI testi

Operasyon:

tıklayın telefonumun kamera açan bir düğme. Resmi çekin ve resmi sdcard depolama birimine kaydedin. Ayrıca tamamlandığında ekranda küçük bir resim görünümünü güncelleyin.

Uygulama iyi çalışıyor, ancak diğer tüm işlemler ve yukarıdaki benzer işlem türleri ile tekrar tekrar manuel olarak test etmek için zaman alıcı bir işlem haline geliyor.

+0

aşağısında mevcut en iyi çözüm bulunmuştur. Kamera uygulaması desteklenemez. UI Automator yerine deneyin: http://developer.android.com/tools/testing/testing_ui.html – haffax

cevap

2

Eğer hala ihtiyacınız varsa, bu akışı test etmek için kullanabileceğiniz etkinlik sonucuna dalga geçen yeni Espresso-Intent'i kullanabilirsiniz. See the sample from Android Testing

+2

Sadece bir düzeltme, doğru bağlantı şu anda https://github.com/googlesamples/android-testing/tree/master/ ui/espresso/IntentsBasicSample – Thalescm

+0

@Thalescm Güncelleme için teşekkürler! – Yenchi

6

Ben benzer bir sorun ile çalışan ve yalnızca uygulama içinde faaliyetlerini test edebilirsiniz Espresso ile bağlantıya 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 gibi bazı cihazlar, kamera uygulamasının "com.sec.android.app.camera" paket adına sahip. Bu çözüm bu cihazda çalışmıyor mu? –