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
The Importance of Being Tested
Search
Roberto Orgiu
October 21, 2021
Programming
430
0
Share
The Importance of Being Tested
Slides of the talk I gave at Droidcon Berlin 2021
Roberto Orgiu
October 21, 2021
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
130
Behind the curtains
tiwiz
0
72
An Android Dev start to Kotlin MPP
tiwiz
0
190
Fantastic API and where to find them
tiwiz
0
85
Flipping the Koin @ GDG Dev Party
tiwiz
1
78
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
GraphQL IRL (Android Makers)
tiwiz
0
160
Other Decks in Programming
See All in Programming
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
160
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
AIエージェントで業務改善してみた
taku271
0
540
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
550
NakouPAY説明用
annouim0
0
270
JAWS-UG横浜 #100 祝・第100回スペシャルAWS は VPC レスの時代へ
maroon1st
0
180
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
290
事業会社でのセキュリティ長期インターンについて
masachikaura
1
270
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
450
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
150
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
190
JOAI2026 1st solution - heron0519 -
heron0519
0
150
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9k
How GitHub (no longer) Works
holman
316
150k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
220
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
200
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
It's Worth the Effort
3n
188
29k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
110
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
Transcript
Roberto Orgiu | Senior Android Engineer @ NYTimes | @_tiwiz
The importance of being tested
What is testing about?
Correctness Functioning
Is everything testable?
class Repository { private val dep = Dependency( ) fun
fetch() = dep.getData( ) }
class Repository ( private val dep: Dependenc y ) {
fun fetch() = dep.getData( ) }
What should I test?
Test the logic, not the code. Fabio Collini (probably?)
fun testCode() { repository.fetch( ) verify(mockDependency).getData( ) }
fun testLogic() { val actualResult = repository.fetch( ) verify(actualResult )
.isEqualTo(expectedResult ) }
Was that unit testing?
Was that unit testing? Is unit testing enough?
cwti.link/twitch
What about integration testing?
What about integration testing? integration tests validate the collaboration and
interaction of a group of units.
My take on integration testing
My take on integration testing •No Android deps •Test fl
ow from start to end •Use Robolectric
class RootFragment : Fragment() { lateinit var repository: Repositor y
lateinit var view: Vie w fun onResume() { val response = repository.fetchThings( ) view.bindResults(response ) } }
class IntegrationTest { private val mock = TestDouble(Service() ) private
val testFragment = RootFragment( ) fun integrationTest() { run(testFragment).verify( ) } } androidTest
What about Network?
What about network? Network is unreliable
What about network? • Retro fi t + OkHttp +
MockWebServer • Ktor + MockEngine
val retrofit = Retrofit.Builder( ) .baseUrl("https://api.github.com/" ) .build( ) This
should come from the outside!
val retrofit = Retrofit.Builder( ) .baseUrl(url ) .build( )
val server = MockWebServer( ) server.enqueue ( MockResponse().setBody("hello, world!" )
) server.start( ) val url = server.url( )
HttpClient(Android) { install(Logging) { … } install(JsonFeature) { … }
} This should come from the outside!
val mockEngine = MockEngine { request - > respond (
content = ByteReadChannel(content) , status = HttpStatusCode.OK , headers = headersOf(ContentType, type ) ) }
What about UI testing?
What about UI testing?
@get:Rule var activityScenarioRule = activityScenarioRule<MyActivity>( ) @Tes t fun changeText()
{ onView(withId(startViewId) ) .perform ( typeText(MESSAGE) , closeSoftKeyboard( ) ) onView(withId(buttonViewId) ) .perform(click() ) onView(withId(targetView) ) .check(matches(withText(MESSAGE)) ) }
None
None
@Composabl e fun SimpleUI() { var clicks by remember {
mutableStateOf(0) } Column { Button ( onClick = { clicks++ } ) { Text(text = "Click me" ) } if (clicks > 0) { Text(text = "$clicks" ) } } }
@get:Rul e val composeTestRule = createComposeRule( ) @Tes t fun
verify_initial_case() { composeTestRule.setContent { SimpleUI( ) } composeTestRule.onNodeWithTag("clicks" ) .assertDoesNotExist( ) }
@get:Rul e val composeTestRule = createComposeRule( ) @Tes t fun
verify_last_case() { composeTestRule.setContent { SimpleUI( ) } composeTestRule.onNodeWithText("Click me" ) .performClick( ) with(composeTestRule.onNodeWithTag("clicks")) { assertIsDisplayed( ) assertTextEquals("1" ) } }
How can I start testing?
Roberto Orgiu | Senior Android Engineer @ NYTimes | @_tiwiz
Thanks for listening. Q&A Time