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
Acceptance test like a pro
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Rodrigo Sicarelli
May 07, 2016
Technology
2
190
Acceptance test like a pro
Tirando vantagem do Espresso e Android Studio para criar testes de aceitação incríveis
Rodrigo Sicarelli
May 07, 2016
Tweet
Share
More Decks by Rodrigo Sicarelli
See All by Rodrigo Sicarelli
Melhores práticas para encontrar Crashes utilizando o CrashLytics
rsicarelli
2
160
Firebase para Desenvolvedores
rsicarelli
4
190
A importância de ter Lazy Clients - TDC 2016
rsicarelli
3
230
Erlang - Why?
rsicarelli
0
74
Android Support Library v23.2.0
rsicarelli
0
57
ProGuard - O que é e porque utilizar
rsicarelli
0
130
Other Decks in Technology
See All in Technology
TypeScript 7.0の現在地と備え方
uhyo
7
2k
The Rise of Browser Automation: AI-Powered Web Interaction in 2026
marcthompson_seo
0
210
システム標準化PMOから ガバメントクラウドCoEへ
techniczna
1
160
TinyTroupeで人狼ゲームやってみた!
ueponx
0
170
詳解 強化学習 / In-depth Guide to Reinforcement Learning
prinlab
0
340
【社内勉強会】新年度からコーディングエージェントを使いこなす - 構造と制約で引き出すClaude Codeの実践知
nwiizo
8
4.8k
AIエージェント×GitHubで実現するQAナレッジの資産化と業務活用 / QA Knowledge as Assets with AI Agents & GitHub
tknw_hitsuji
0
130
スピンアウト講座04_ルーティン処理
overflowinc
0
320
VPCエンドポイント意外とお金かかるなぁ。せや、共有したろ!
tommy0124
1
720
Bill One 開発エンジニア 紹介資料
sansan33
PRO
5
18k
Phase01_AI座学_基礎
overflowinc
0
1.1k
Phase03_ドキュメント管理
overflowinc
0
710
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
110
First, design no harm
axbom
PRO
2
1.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
140
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
AI: The stuff that nobody shows you
jnunemaker
PRO
3
460
Testing 201, or: Great Expectations
jmmastey
46
8.1k
HDC tutorial
michielstock
1
570
What does AI have to do with Human Rights?
axbom
PRO
1
2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
240
[SF Ruby Conf 2025] Rails X
palkan
2
840
Prompt Engineering for Job Search
mfonobong
0
210
Faster Mobile Websites
deanohume
310
31k
Transcript
Rodrigo Sicarelli Acceptance test like a pro Tirando vantagem do
Espresso
Android Dev BR medium.com/android-dev-br androiddevbr.org +1100 membros Novo artigo toda
semana Newsletter semanal Canal direto com GDE’s Codehelp, feedbacks, learn etc etc etc
OpenMovie github.com/rsicarelli/openmovie
Acceptance tests
Acceptance tests
The sad truth
May the user be with you
Hermetic testing testdroid.com/tech/strive-for-hermetic-but-never-compromise-integrity-of-app
Hermetic testing
Hermetic testing semaphoreci.com/community/tutorials/how-to-deal-with-and-eliminate-flaky-tests
External dependencies Your code
Isolate all the external dependencies Your code
Create an fake environment!
Product flavors developer.android.com/intl/pt-br/tools/building/configuring-gradle
The “mock" flavor debug release prod mock android-developers.blogspot.com.br/2015/12/leveraging-product-flavors-in-android
The “mock" flavor codelabs.developers.google.com/codelabs/android-testing
Which one should I use? View Network
Which one should I use? View Network Injection medium.com/@patrykpoborca/making-a-best-practice-app-4-dagger-2-267ec5f6c89a#.iwom3rir5
Which one should I use? google.github.io/dagger blog.sqisland.com/2016/01/daggerless-di-testing
MovieClient @Override public void findMoviesByQuery(String query, Callback callback) {} @Override
public void findMovieById(String id, Callback callback) {}
ClientModule @Module public class ClientModule { @Provides public MovieClient provideMovieClient()
{ return new MovieClient(); } }
Our Presenter public class Presenter { @Inject MovieClient client; }
Structure
Our prod flavor @Override public void findMoviesByQuery(String query, Callback callback)
{ //Calling the API; } @Override public void findMovieById(String id, Callback callback) { //Calling the API; }
Our mock flavor @Override public void findMoviesByQuery(String query, Callback callback)
{ //Return a fake json; } @Override public void findMovieById(String id, Callback callback) { //Return a fake json; }
Isolate all the external dependencies Your code
Not today, son.
Login screen play.google.com/store/apps/details?id=br.com.elo7.appbuyer
Login screen Is the Activity open? Can I perform some
click? etc etc etc
In Espresso we trust developer.android.com/intl/pt-br/reference/android/app/Instrumentation
My activity is open? waitForActivity() and waitForActivityWithTimeout() developer.android.com/intl/pt-br/reference/android/app/Instrumentation.ActivityMonitor
Using the ActivityMonitor public void registerMonitor(Class<? extends Activity> activityClass) {
if (monitor != null) { getInstrumentation().removeMonitor(monitor); } monitor = new Instrumentation.ActivityMonitor(activityClass.getName(), null, false); getInstrumentation().addMonitor(monitor); } @Test public void shouldTestSomething() { onView(withId(R.id.login)).perform(click()); monitor.waitForActivity(); onData(anything()) .inAdapterView(withId(R.id.product_grid_view)) .atPosition(0) .perform(click()); } public class BaseActivityTestCase extends ActivityTestCase {...}
Using the Monitor @Test public void shouldTestSomething() { onView(withId(R.id.login)).perform(click()); monitor.waitForActivity();
registerMonitor(OtherActivity.class); onData(anything()) .inAdapterView(withId(R.id.product_grid_view)) .atPosition(0) .perform(click()); monitor.waitForActivity();//new monitor! }
Searching while typing
In Espresso we trust! developer.android.com/intl/pt-br/reference/android/support/test/espresso/IdlingResource
Usage public final class SimpleCountingIdlingResource implements IdlingResource {…} public class
EspressoIdlingResource { ... public static void busy() { simpleCountingIdlingResource.increment(); } public static void idle() { simpleCountingIdlingResource.decrement(); } ... }
Usage @Override public void findMoviesByQuery(String query, Callback callback) { EspressoIdlingResource.busy();
... searchResponseCall.enqueue(... { @Override public void onResponse(...) { EspressoIdlingResource.idle(); } @Override public void onFailure(...) { EspressoIdlingResource.idle(); } }); }
Usage @Before private void registerIdlingResource() { Espresso.registerIdlingResources( rule.getActivity().getCountingIdlingResource()); } @After
public void unregisterIdlingResource() { Espresso.unregisterIdlingResources( rule.getActivity().getCountingIdlingResource()); }
Oh yeah
Next steps Inject modules inside the tests Remove test code
Acceptance test like a pro Tirando vantagem do Espresso +RodrigoSicarelli2
[email protected]
github.com/rsicarelli/openmovie androiddevbr.org