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
26
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
80
Behind the curtains
tiwiz
0
24
The Importance of Being Tested
tiwiz
0
310
An Android Dev start to Kotlin MPP
tiwiz
0
110
Fantastic API and where to find them
tiwiz
0
40
Flipping the Koin @ GDG Dev Party
tiwiz
1
34
Flipping the Koin
tiwiz
2
120
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
66
Trip into the async world
tiwiz
1
87
Other Decks in Programming
See All in Programming
3 Effective Rules for Success with Signals in Angular
manfredsteyer
PRO
0
120
英語
s_shimotori
1
220
データカタログ運用物語 〜令和6年夏の理想と現実〜
kuro_kurorrr
0
110
CSC307 Lecture 14
javiergs
PRO
0
220
CSC307 Lecture 13
javiergs
PRO
0
150
feature環境をGitHub ActionsとCloudFormationでいい感じに管理する
nealle
2
310
Namespace on read
tagomoris
2
370
I/O Extended Android in Korea 2024 ~ Whats new in Android development tools
pluu
0
250
Google's Recipe for Scaling (Web) Security – LocoMocoSec 2024
lweichselbaum
0
170
DynamoDB コスト最適化っぽいことの基本 with Terraform
kuro_kurorrr
2
250
CSC307 Lecture 09
javiergs
PRO
1
500
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
517
39k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
18
1.2k
Designing the Hi-DPI Web
ddemaree
276
34k
[RailsConf 2023] Rails as a piece of cake
palkan
35
4.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
35
6.3k
Infographics Made Easy
chrislema
238
18k
How To Stay Up To Date on Web Technology
chriscoyier
784
250k
Designing for Performance
lara
604
67k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
129
32k
Rebuilding a faster, lazier Slack
samanthasiow
78
8.5k
How to train your dragon (web standard)
notwaldorf
79
5.5k
GitHub's CSS Performance
jonrohan
1026
450k
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!