Executar testes é uma etapa importante do processo de desenvolvimento para garantir níveis de qualidade aceitáveis pelos usuários de sua aplicação. No entanto com o aumento do número de funcionalidades e as frequentes ondas de novos devices esta tarefa tem se tornado cada vez mais árdua, além de extremamente repetitiva, tediosa e sujeita à erros. No mundo Android algumas ferramentas podem lhe auxiliar a automatizar seu processo de testes, o Espresso e o UIAutomator são duas delas que recentemente foram adicionadas ao Android Testing Framework. Nesta palestra trataremos de como utilizar estes frameworks em seu projeto Android para automatizar e simular a interação do usuário com sua app e validar funcionalidades de sua aplicação no processo tornando o seu dia mais legal e produtivo.
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
10. Intel Software and Services Group
Espresso
11
• Simplifies the UI Test
Process within your App
• Methods for:
• View matching
• Checks
• UI Events
11. Intel Software and Services Group 12
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 13
Espresso – Vilibra Case
• Virtual Librarian
• Help to remember the books I
lend
• How to automate the lend
details view?
• Class:
TestViewLendedBookDetailFlow
13. Intel Software and Services Group 14
Check the code!
Instrumented Test Package:
vilibra/app/src/main/androidTest/java/ecarrara/eng/vilibra/
Test Class:
TestViewLendedBookDetailFlow.java
14. Intel Software and Services Group
UI Automator
24
• Cross App Testing
• Instrumentation Based
• Interact with visible
elements using
descriptors (like text).
15. Intel Software and Services Group 25
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'
}
16. Intel Software and Services Group
1. Extend the InstrumentationTestCase class.
2. Get an instance of UIDevice.
3. Use the method UIDevice.findObject() to get UIObjects and
execute Actions.
4. Use asserts to check the results.
26
UIAutomator – Primeiro Test Case
18. Intel Software and Services Group 28
UIAutomator – Vilibra Case
• New case: automate the entire
lend process test.
• Class: TestLendBookFlow
19. Intel Software and Services Group 29
Check the code!
Instrumented Test Package:
vilibra/app/src/main/androidTest/java/ecarrara/eng/vilibra/
Test Class:
TestLendBookFlow.java
20. Intel Software and Services Group 44
Fragmentation
Screen size/density variety
Different Processor
Many OS versions
24. Intel Information Technology
What is next?
52
• 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
25. Intel Software and Services Group 53
Intel Developer Zone
https://software.intel.com/en-us/android/app-testing
26. Intel Software and Services Group
Thanks!
54
+EduardoCarraraDeAraujo
https://www.facebook.com/ducarrara
@DuCarrara
br.linkedin.com/in/eduardocarrara/
ecarrara-araujo/vilibra