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
75
Behind the curtains
tiwiz
0
24
The Importance of Being Tested
tiwiz
0
280
An Android Dev start to Kotlin MPP
tiwiz
0
100
Fantastic API and where to find them
tiwiz
0
35
Flipping the Koin @ GDG Dev Party
tiwiz
1
33
Flipping the Koin
tiwiz
2
120
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
63
Trip into the async world
tiwiz
1
84
Other Decks in Programming
See All in Programming
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
970
Tailwind CSSを本気でカスタマイズする方法
fsubal
14
5.5k
Documentation for users with AsciiDoc and Antora
ahus1
0
370
Milestoner
bkuhlmann
1
410
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
180
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
220
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
280
Next.js App Router
quramy
12
1.8k
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
1k
Going beyond Apache Parquet's default settings
xhochy
0
130
GitLab CI/CD で C#/WPFアプリケーションのテストとインストーラーのビルド・デプロイを自動化する
hacarus
0
280
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
660
120k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
20
1.8k
Stop Working from a Prison Cell
hatefulcrawdad
267
19k
Building a Modern Day E-commerce SEO Strategy
aleyda
21
6.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
188
16k
YesSQL, Process and Tooling at Scale
rocio
165
13k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
Into the Great Unknown - MozCon
thekraken
14
1k
Web Components: a chance to create the future
zenorocha
306
41k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
123
39k
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!