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
Roberto Orgiu
March 26, 2019
Programming
0
36
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
67
The Importance of Being Tested
tiwiz
0
420
An Android Dev start to Kotlin MPP
tiwiz
0
180
Fantastic API and where to find them
tiwiz
0
77
Flipping the Koin @ GDG Dev Party
tiwiz
1
74
Flipping the Koin
tiwiz
2
160
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
120
Trip into the async world
tiwiz
1
140
Other Decks in Programming
See All in Programming
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
3
1.2k
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
230
[SF Ruby Feb'26] The Silicon Heel
palkan
0
120
AHC061解説
shun_pi
0
410
Everything Claude Code OSS詳細 — 5層構造の中身と導入方法
targe
0
140
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
190
AI 開発合宿を通して得た学び
niftycorp
PRO
0
160
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
190
技術検証結果の整理と解析をAIに任せよう!
keisukeikeda
0
130
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.3k
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
250
PHP 7.4でもOpenTelemetryゼロコード計装がしたい! / PHPerKaigi 2026
arthur1
1
320
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
320
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.5k
A designer walks into a library…
pauljervisheath
210
24k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.4k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
490
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
500
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
We Are The Robots
honzajavorek
0
200
Exploring anti-patterns in Rails
aemeredith
2
290
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!