$30 off During Our Annual Pro Sale. View Details »
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
0
410
The Importance of Being Tested
Slides of the talk I gave at Droidcon Berlin 2021
Roberto Orgiu
October 21, 2021
Tweet
Share
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
120
Behind the curtains
tiwiz
0
60
An Android Dev start to Kotlin MPP
tiwiz
0
170
Fantastic API and where to find them
tiwiz
0
72
Flipping the Koin @ GDG Dev Party
tiwiz
1
68
Flipping the Koin
tiwiz
2
160
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
110
Trip into the async world
tiwiz
1
130
GraphQL IRL (Android Makers)
tiwiz
0
150
Other Decks in Programming
See All in Programming
脳の「省エネモード」をデバッグする ~System 1(直感)と System 2(論理)の切り替え~
panda728
PRO
0
120
TestingOsaka6_Ozono
o3
0
170
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
190
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3k
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
140
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
440
AIコーディングエージェント(NotebookLM)
kondai24
0
230
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.3k
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
890
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
280
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
130
Featured
See All Featured
Visualization
eitanlees
150
16k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Documentation Writing (for coders)
carmenintech
77
5.2k
Balancing Empowerment & Direction
lara
5
820
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
45
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
190
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
94
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
So, you think you're a good person
axbom
PRO
0
1.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Facilitating Awesome Meetings
lara
57
6.7k
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