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
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
AI との良い付き合い方を僕らは誰も知らない
asei
0
270
AIBuildersDay_track_A_iidaxs
iidaxs
4
1.4k
まだ間に合う! Agentic AI on AWSの現在地をやさしく一挙おさらい
minorun365
17
2.8k
半年で、AIゼロ知識から AI中心開発組織の変革担当に至るまで
rfdnxbro
0
150
Next.js 16の新機能 Cache Components について
sutetotanuki
0
190
2025年のデザインシステムとAI 活用を振り返る
leveragestech
0
330
Agent Skillsがハーネスの垣根を超える日
gotalab555
6
4.5k
モダンデータスタックの理想と現実の間で~1.3億人Vポイントデータ基盤の現在地とこれから~
taromatsui_cccmkhd
2
270
AWS運用を効率化する!AWS Organizationsを軸にした一元管理の実践/nikkei-tech-talk-202512
nikkei_engineer_recruiting
0
170
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
9.9k
たまに起きる外部サービスの障害に備えたり備えなかったりする話
egmc
0
420
日本の AI 開発と世界の潮流 / GenAI Development in Japan
hariby
1
500
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
54
7.9k
Accessibility Awareness
sabderemane
0
24
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
Side Projects
sachag
455
43k
Speed Design
sergeychernyshev
33
1.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Ethics towards AI in product and experience design
skipperchong
1
140
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
How STYLIGHT went responsive
nonsquared
100
6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
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