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
Sharing (tests) is caring ❤️
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Roberto Orgiu
March 26, 2019
Programming
0
37
Sharing (tests) is caring ❤️
Roberto Orgiu
March 26, 2019
Tweet
Share
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
120
Behind the curtains
tiwiz
0
68
The Importance of Being Tested
tiwiz
0
420
An Android Dev start to Kotlin MPP
tiwiz
0
190
Fantastic API and where to find them
tiwiz
0
80
Flipping the Koin @ GDG Dev Party
tiwiz
1
75
Flipping the Koin
tiwiz
2
170
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
120
Trip into the async world
tiwiz
1
150
Other Decks in Programming
See All in Programming
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
270
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
300
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
160
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
1.4k
Codex の「自走力」を高める
yorifuji
0
1.3k
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
290
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
200
PHPのバージョンアップ時にも役立ったAST(2026年版)
matsuo_atsushi
0
270
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
480
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
100
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
240
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Navigating Weather and Climate Data
rabernat
0
150
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
850
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
1.9k
Skip the Path - Find Your Career Trail
mkilby
1
93
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
270
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
260
Transcript
SHARING (TESTS) IS CARING
THE ISSUE Device tests are slow. Like real slow.
A HACKY SOLUTION Running Android tests on JVM
SHARED FOLDER Same level as androidTest and test. Same structure
as well.
android { ... sourceSets { String sharedTestDir = 'src/sharedTest/java' test
{ java.srcDir sharedTestDir } androidTest { java.srcDir sharedTestDir } } } What happens in build.gradle stays in build.gradle
testImplementation 'androidx.test:runner:1.1.1' testImplementation 'androidx.test.espresso:espresso-core:3.1.1' testImplementation 'androidx.test.ext:junit:1.1.0' testImplementation 'org.robolectric:robolectric:4.1' androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.0' We ❤ dependencies
testImplementation 'androidx.test:runner:1.1.1' testImplementation 'androidx.test.espresso:espresso-core:3.1.1' testImplementation 'androidx.test.ext:junit:1.1.0' testImplementation 'org.robolectric:robolectric:4.1' androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.0' We ❤ dependencies
Everything always works as planned — Nobody ever
testOptions { unitTests { includeAndroidResources = true returnDefaultValues = true
} } JVM needs to know, after all.
@RunWith(AndroidJUnit4::class) class MainActivityTest { @Test fun simple_test() { ActivityScenario.launch(MainActivity::class.java) onView(withId(R.id.fab)).check(matches(isDisplayed()))
} }
@RunWith(AndroidJUnit4::class) class MainActivityTest { @Test fun simple_test() { ActivityScenario.launch(MainActivity::class.java) onView(withId(R.id.fab)).check(matches(isDisplayed()))
} } It wouldn't really work without that
RUNNING TESTS
DEVICE TESTS
JVM TESTS
Test configuration should have different names — Me. So it's
true.
FUN FACT
Default is Device tests! — Me again.
WAIT A MINUTE !
IF BOTH CONFIGURATIONS CAN SEE SHARED TESTS...
... DOES IT MEAN JENKINS WOULD RUN THEM TWICE?
YES!
BUT THAT IS A PROBLEM
YES!
BUT WE CAN FIX IT! !
! EXCLUDE SOME TESTS!
interface DoNotRunOnJvm Inside sharedTest folder
testOptions { ... unitTests.all { useJUnit { excludeCategories 'net.orgiu.tests.DoNotRunOnJvm' }
} } Once more in build.gradle
testOptions { ... unitTests.all { useJUnit { excludeCategories 'net.orgiu.tests.DoNotRunOnJvm' }
} } Once more in build.gradle
... AND FINALLY @RunWith(AndroidJUnit4::class) @Category(DoNotRunOnJvm::class) class MainActivityTest { @Test fun
simple_test() { ActivityScenario.launch(MainActivity::class.java) onView(withId(R.id.fab)).check(matches(isDisplayed())) } }
... AND FINALLY @RunWith(AndroidJUnit4::class) @Category(DoNotRunOnJvm::class) class MainActivityTest { @Test fun
simple_test() { ActivityScenario.launch(MainActivity::class.java) onView(withId(R.id.fab)).check(matches(isDisplayed())) } }
REMEMBER TO TEST
YOU'RE BEING WATCHED.
! THANKS FOR WATCHING!