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
150
Firebase para Desenvolvedores
rsicarelli
4
180
A importância de ter Lazy Clients - TDC 2016
rsicarelli
3
220
Erlang - Why?
rsicarelli
0
64
Android Support Library v23.2.0
rsicarelli
0
50
ProGuard - O que é e porque utilizar
rsicarelli
0
130
Other Decks in Technology
See All in Technology
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
The Role of Developer Relations in AI Product Success.
giftojabu1
0
130
複雑なState管理からの脱却
sansantech
PRO
1
150
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.7k
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
170
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
310
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Being A Developer After 40
akosma
87
590k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Designing for Performance
lara
604
68k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Writing Fast Ruby
sferik
627
61k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Building Adaptive Systems
keathley
38
2.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
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