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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Rodrigo Sicarelli
May 07, 2016
Technology
200
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
More Decks by Rodrigo Sicarelli
See All by Rodrigo Sicarelli
Melhores práticas para encontrar Crashes utilizando o CrashLytics
rsicarelli
2
180
Firebase para Desenvolvedores
rsicarelli
4
200
A importância de ter Lazy Clients - TDC 2016
rsicarelli
3
240
Erlang - Why?
rsicarelli
0
78
Android Support Library v23.2.0
rsicarelli
0
64
ProGuard - O que é e porque utilizar
rsicarelli
0
150
Other Decks in Technology
See All in Technology
【CEDEC2026】専門性の高いデフォルメチームが挑んだ人材育成戦略 〜Cygames Academiaの企画から実施まで〜
cygames
PRO
0
610
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
LLM・AIエージェントシステムベストプラクティス
shibuiwilliam
6
1.2k
Bits Agent Builder の⼊⾨と活⽤事例
nulabinc
PRO
0
140
【CEDEC2026】グラフィックスエンジニアのためのニューラルシェーディング入門
cygames
PRO
0
150
攻撃と防御で学ぶAI時代のプロダクトセキュリティ演習
recruitengineers
PRO
9
2.8k
生成 AI の基礎 〜 サンプル実装で学ぶ基本原理
enakai00
7
4.4k
Eight Engineering Unit 紹介資料
sansan33
PRO
3
8.2k
オートロックマンションなのに、各部屋は施錠なし!? 攻撃者が組織内ネットワークで大暴れする理由 / The Front Door Is Locked, but the Rooms Are Wide Open: Why Attackers Move Freely Inside Enterprise Networks
nttcom
1
4.7k
SmartHR Engineering Team Deck
smarthr
1
2.1k
侵入は突然に 〜 IoTマルウェアと悪用される家庭の機器 ~ / When Intrusion Strikes: IoT Malware and the Abuse of Home Devices
nttcom
0
4.6k
ガバメント AI 源内を地方自治体は活用できるのか可能性と課題、期待について
takeda_h
1
410
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Being A Developer After 40
akosma
91
590k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
640
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
430
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The SEO Collaboration Effect
kristinabergwall1
1
520
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
430
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
250
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