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
27
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
91
Behind the curtains
tiwiz
0
34
The Importance of Being Tested
tiwiz
0
360
An Android Dev start to Kotlin MPP
tiwiz
0
130
Fantastic API and where to find them
tiwiz
0
48
Flipping the Koin @ GDG Dev Party
tiwiz
1
36
Flipping the Koin
tiwiz
2
140
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
77
Trip into the async world
tiwiz
1
97
Other Decks in Programming
See All in Programming
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
130
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
150
CI改善もDatadogとともに
taumu
0
120
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
110
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
740
パスキーのすべて ── 導入・UX設計・実装の紹介 / 20250213 パスキー開発者の集い
kuralab
3
780
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
840
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
仕様変更に耐えるための"今の"DRY原則を考える / Rethinking the "Don't repeat yourself" for resilience to specification changes
mkmk884
0
160
Spring gRPC について / About Spring gRPC
mackey0225
0
220
iOSエンジニアから始める visionOS アプリ開発
nao_randd
3
130
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.4k
Into the Great Unknown - MozCon
thekraken
35
1.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
133
33k
A Modern Web Designer's Workflow
chriscoyier
693
190k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
A designer walks into a library…
pauljervisheath
205
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Unsuck your backbone
ammeep
669
57k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
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!