Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Espresso 101: Introdução a UI Testing
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Pedro Salomão
January 25, 2016
Technology
0
42
Espresso 101: Introdução a UI Testing
Introdução a testes de interface gráfica usando o Framework Espresso, da Google.
Pedro Salomão
January 25, 2016
Tweet
Share
More Decks by Pedro Salomão
See All by Pedro Salomão
Segurança no Desenvolvimento de App`s
ppgsalomao
1
66
Testes Unitários no Android Studio
ppgsalomao
0
120
Persistência com Realm.io
ppgsalomao
4
160
Other Decks in Technology
See All in Technology
PMとしての意思決定とAI活用状況について
lycorptech_jp
PRO
0
140
Claude Code のコード品質がばらつくので AI に品質保証させる仕組みを作った話 / A story about building a mechanism to have AI ensure quality, because the code quality from Claude Code was inconsistent
nrslib
13
8.6k
Scrumは歪む — 組織設計の原理原則
dashi
0
200
内製AIチャットボットで学んだDatadog LLM Observability活用術
mkdev10
0
130
AI駆動AI普及活動 ~ 社内AI活用の「何から始めれば?」をAIで突破する
oracle4engineer
PRO
1
110
Lambda Web AdapterでLambdaをWEBフレームワーク利用する
sahou909
0
170
Everything Claude Code を眺める
oikon48
11
7.3k
Go標準パッケージのI/O処理をながめる
matumoto
0
220
VPCエンドポイント意外とお金かかるなぁ。せや、共有したろ!
tommy0124
1
690
AlloyDB 奮闘記
hatappi
0
150
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
390
今のWordPress の制作手法ってなにがあんねん?(改) / What’s the Deal with WordPress Development These Days?
tbshiki
0
500
Featured
See All Featured
Skip the Path - Find Your Career Trail
mkilby
1
84
Agile that works and the tools we love
rasmusluckow
331
21k
Producing Creativity
orderedlist
PRO
348
40k
WCS-LA-2024
lcolladotor
0
480
A Tale of Four Properties
chriscoyier
163
24k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
190
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
450
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
120
Transcript
Espresso 101: Introdução a UI Testing Pedro Salomão @ppgsalomao
[email protected]
/
[email protected]
#whoami
Objetivos
Objetivos 1. Onde entram as diversas ferramentas de teste; 2.
O que são Testes de Interface do Usuário; 3. Como definir o que testar; 4. Como integrar o Espresso ao meu projeto; 5. Como escrever o meu primeiro teste de UI; 6. [BÔNUS] Demo.
Ferramentas para Teste
Camadas da Aplicação USUÁRIO APK INTERNET Interface Gráfica
Ferramentas para Teste Robolectric API 16+ JVM Espresso API 8+
Robotium Calabash Selendroid Instrumentation API 1+ Android Platform Appium UIAutomator API 16+ UIAutomation API 18+
Ferramentas para Teste Robolectric API 16+ JVM Espresso API 8+
Robotium Calabash Selendroid Instrumentation API 1+ Android Platform Appium UIAutomator API 16+ UIAutomation API 18+
Camadas da Aplicação USUÁRIO ESPRESSO APK INTERNET Interface Gráfica
Testes de Interface
Testes de Interface 1. O que devo testar? 2. Qual
o escopo de um teste (método)? 3. Posso testar fluxos completos? 4. E como funciona o estado da aplicação? 5. O que é um Mock e por que é importante?
None
Espresso Processo APK Test APK Espresso
Vamos falar de código?!
Integrando o Espresso
Integrando o Espresso 1. Adicionar no build.gradle, em dependencies: 2.
Adicionar no build.gradle, em android.defaultConfig: compile 'com.android.support:support-annotations:23.1.1' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test:runner:0.4.1' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" fonte: https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html
Escrevendo o Teste
Espresso - Asserts onView( ViewMatcher ) .perform( ViewAction ) .check(
ViewAssertion ) fonte: https://google.github.io/android-testing-support-library/docs/espresso/cheatsheet/index.html
ViewMatcher Dois usos básicos: • Encontrar uma view (onView) •
Verificar uma condição da View (matches) Exemplos: • withId( … ) • withText( … ) • isDisplayed()
ViewAction Permite executar ações na tela. Exemplos: • click() •
scrollTo( … ) • typeText( … )
ViewAssertion Permite verificar uma determinada propriedade. Exemplos: • matches( Matcher
) • doesNotExists( … ) • typeText( … ) Observação: doesNotExists() != isNotDisplayed()
Criando um teste Passos para criar um Teste usando Espresso:
• Adicionar a anotação do JUnit na classe. • Adicionar uma Rule para a Activity a ser testada. • Criar os métodos de teste.
Exemplo @RunWith(AndroidJUnit4.class) @LargeTest public class HelloWorldEspressoTest { @Rule public ActivityTestRule<MainActivity>
mActivityRule = new ActivityTestRule<>(MainActivity.class); @Test public void listGoesOverTheFold() { onView(withText("Hello world!”)) .check(matches(isDisplayed())); } }
DEMO
Links Úteis Site da Google para Android Testing https://google.github.io/android-testing-support-library/ Código
do Demo de Espresso https://github.com/ppgsalomao/espresso-examples GTAC 2014: Espresso, Spoon, Wiremock, Oh my! https://www.youtube.com/watch?v=-xQCNf_5NNM Droidcon NYC 2015 - Advanced Android Espresso https://www.youtube.com/watch?v=GlPn60-_txk
Dúvidas?
Obrigado! Pedro Salomão @ppgsalomao
[email protected]
/
[email protected]