Palestra apresentando os primeiros passos na utilização do JUnit, Espresso e UIAutomator para a automação de testes em Apps Android, além de como utilizar os testes criados em uma device farm na nuvem para execução dos testes.
Para vídeos sobre o funcionamento do TestDroid verifique o canal deles no YouTube: https://www.youtube.com/user/BitbarChannel
4. Intel Information Technology
“I choose a lazy person to do a hard job.
Because a lazy person will find an easy way to do it.”
- Bill Gates
4
Image by Karla Vidal @ http://www.flickr.com/photos/63721650@N00/3661526274
Creative Commons cc-by-2.0
8. Intel Software and Services Group 9
JUnit
@RunWith(AndroidJUnit4.class)
public class SimpleTest {
@Before public void setUp() { }
@Test public void testSomething() { }
@After public void cleanUp() { }
}
10. Intel Software and Services Group
Espresso
12
• Simplifies the UI Test
Process within your App
• Methods for:
• View matching
• Checks
• UI Events
11. Intel Software and Services Group 13
Espresso - Configuration
dependencies {
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}
build.gradle
Desabilitar nas opções do desenvolvedor (no device):
• Window Animation Scale
• Transition Animation Scale
• Animator Duration Scale
12. Intel Software and Services Group 14
Espresso – Trecho Mínimo de Código
Espresso Cheat Sheet
@Test public void testSuccessfulAwesomeFeature() {
//na view com o id myViewId faça um doubleClick
onView(withId(myViewId)).perform(doubleClick());
}
Entry Point
Critério
de
Seleção da View
Ação
Na
ViewInteraction
Critérios
Da
Ação
13. Intel Software and Services Group 15
Espresso – Vilibra Case
• Virtual Librarian
• Help to remember the books I
lend
• How to automate the lend
details view?
• Class:
TestViewLendedBookDetailFlow
14. Intel Software and Services Group 16
Check the code!
Instrumented Test Package:
vilibra/app/src/main/androidTest/java/ecarrara/eng/vilibra/
Test Class:
TestViewLendedBookDetailFlow.java
15. Intel Software and Services Group
UIAutomator
26
• Cross App Testing
• Instrumentation Based
• Interact with visible
elements using
descriptors (like text).
16. Intel Software and Services Group 27
UIAutomator - Configuração
build.gradle
É necessário inspecionar os componentes visuais das apps alvo para garantir que o
UIAutomator consiga localizá-los.
Isso significa ter labels de texto visíveis, a propriedade android:contentDescription
preenchida, ou ainda a propriedade android:hint (para EditTexts)
dependencies {
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-
v18:2.1.1'
}
17. Intel Software and Services Group 28
UIAutomator – Trecho Minimo de Código
@Test public void myAwesomeTest() throws UiObjectNotFoundException {
// encontre o objeto com as caracteristicas e faça um click
mUiDevice.findObject(
new UiSelector()
.className("class-name")
.resourceId("resource-id")
.text("view-text"))
.click();
}
Testing UI for Multiple Apps
Entry Point
Critérios
de
Seleção da View
Ação
no
UIObject
19. Intel Software and Services Group 31
UIAutomator – Vilibra Case
• New case: automate the entire
lend process test.
• Class: TestLendBookFlow
20. Intel Software and Services Group 32
Check the code!
Instrumented Test Package:
vilibra/app/src/main/androidTest/java/ecarrara/eng/vilibra/
Test Class:
TestLendBookFlow.java
21. Intel Software and Services Group 47
Fragmentation
Screen size/density variety
Different Processor
Many OS versions
26. Intel Information Technology
What is next?
56
• Go ahead and automate your app testing!
• How to integrate continous integration and delivery with Android?
• Code Coverage
• Mocking
“If you don’t like testing your product, most likely your
customers won’t like to test it either.”
- Anonymous
27. Intel Software and Services Group 57
Intel Developer Zone
https://software.intel.com/en-us/android/app-testing
28. Intel Software and Services Group
Thanks!
58
+EduardoCarraraDeAraujo
https://www.facebook.com/ducarrara
@DuCarrara
br.linkedin.com/in/eduardocarrara/
ecarrara-araujo/vilibra