SlideShare a Scribd company logo
Gilang Ramadhan
Academy Content Writer Dicoding
Associate Android Developer
Play with Testing on Android
Play with
Testing?
Specifications of the
application
Write the codes
Test the application manually
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
New Feature,
New Bugs...
How to get started?
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
⬅, ➡,
L1, L2, R1, R2,
⬆, ⬇, ⬅, ➡
Android
Jetpack
Source : Android Jetpack
Follow best practices
Built around modern design practices, Android Jetpack
Libraries enable fewer crashes and less memory leaks with
backwards-compatibility baked in.
Eliminate boilerplate code
Android Jetpack manages tedious activities like background
tasks, navigation, and lifecycle management, so you can focus
on what makes your app great.
Reduce fragmentation
Reduce complexity with libraries that work consistently across
Android versions and devices.
Why use Android Jetpack?
Test
Speed Scope Fidelity
Speed
Scope
Fidelity
#of test
Testing Terminology
“The percentage of your
code that is executed by
your tests”
Test Coverage
Test Coverage
Test Driven Development
The two cycles associated with iterative, test-driven development
Source : Fundamentals of Testing
is an application development method developed by
testing.
● Writing Tests
● Running Tests
● Write down the Code
● Running Tests
● Refactor Code
Test Driven Development
● More Productive
● Code is neater Safer
● Refactoring
● Minimizing Bug
● Documentation
Advantages of using TDD
Test Doubles
● Do not mock types you don’t own
● Don’t mock value objects
● Don’t mock everything
● Show love with your tests!
Test Doubles
Given, When, Then
“Arrange, Act,
Assert”
Example
Architecture Pattern
REPLACE ME
The important features of a testable architecture are:
● Each class should have a clearly
defined purpose.
● Limit and be explicit about which
classes know about other classes.
● Use constructor injection.
● Keep Android code out of the view
model.
Architecture Pattern
1. Local unit tests
Located at module-name/src/test/java/.
2. Instrumented tests
Located at module-name/src/androidTest/java/.
1. Run Toolbar.
2. Testing Toolbar.
3. Context Menu.
4. Test Status Icon.
5. Jump to Code.
Unit Test
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Instrumented Test
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)
Let’s Try Together
Source:
● Advanced Android in Kotlin 05.1: Testing
Basics Updated
● Advanced Android in Kotlin 05.2:
Introduction to Test Doubles and
Dependency Injection
● Advanced Android in Kotlin 05.3: Survey of
Testing Topics
What we've covered:
● How to run tests from Android Studio.
● The difference between local (test) and
instrumentation tests (androidTest).
● How to write local unit tests using JUnit and
Hamcrest.
● Setting up ViewModel tests with the AndroidX Test
Library.
Testing Basics Updated
What we've covered:
● What you want to test and your testing strategy determine the kinds of test you are
going to implement for your app. Unit tests are focused and fast. Integration
tests verify interaction between parts of your program. End-to-end tests verify
features, have the highest fidelity, are often instrumented, and may take longer to
run.
● The architecture of your app influences how hard it is to test.
● To isolate parts of your app for testing, you can use test doubles. A test double is a
version of a class crafted specifically for testing. For example, you fake getting
data from a database or the internet.
● Use dependency injection to replace a real class with a testing class, for example,
a repository or a networking layer.
● Use instrumented testing (androidTest) to launch UI components.
● When you can't use constructor dependency injection, for example to launch a
fragment, you can often use a service locator. The Service Locator pattern is an
alternative to Dependency Injection. It involves creating a singleton class called
the "Service Locator", whose purpose is to provide dependencies, both for the
regular and test code.
Introduction to Test Doubles
and Dependency Injection
What we've covered:
● A review of testing coroutines from previous lessons, including
covering the usage of runBlocking versus runBlockingTest.
● How to test coroutines that use viewModelScope by using
TestCoroutineDispatcher
● TestCoroutineDispatcher's ability to pauseDispatcher and
resumeDispatcher to control coroutine execution
● Testing error handling by updating a fake
● Testing your data layer, including your DAO and local data source
● Using IdlingResource (and the CountingIldingResource subclass)
to write end to end tests that both include long running code and
work with the data binding library.
● Testing global app navigation in an end to end test.
Survey of Testing Topics
Advantages of Testing
Testing also provides you with the following
advantages:
● Rapid feedback on failures.
● Early failure detection in the
development cycle.
● Safer code refactoring, letting you
optimize code without worrying about
regressions.
● Stable development velocity, helping
you minimize technical debt.
“Code without tests is bad code”
Michael Feathers, Working Effectively with Legacy Code
REPLACE ME
Belajar Android
Jetpack PRO
Contact:
gilang@dicoding.com
www.dicoding.com
Follow us: @dicoding
Credit:
Unsplash
Google
Pexels

More Related Content

What's hot (18)

PPTX
What Is Cucumber?
QATestLab
 
PPTX
Code review process with JetBrains UpSource
Oleksii Prohonnyi
 
ODP
Continous integration
Jeremy Wilken
 
PDF
Efficient mobile automation
Vitaly Tatarinov
 
PDF
Code Review Tool Evaluation
Kate Semizhon
 
PDF
Code Review
Tu Hoang
 
PPT
Continous Integration: A Case Study
Talentica Software
 
PDF
Robot framework - SAST Väst Q3
Anders Arnholm
 
PPTX
Choosing the Best Open Source Test Automation Tool for You
Perfecto by Perforce
 
ODP
BDD with Cucumber
Knoldus Inc.
 
PPT
Test Driven Development
John Blanco
 
PPT
Test-Driven Development
Effective
 
PPT
Test-Driven Development
EffectiveUI
 
PPTX
Elements of a Test Framework
SmartBear
 
PDF
Quality Built In @ Spotify
Andrii Dzynia
 
PDF
Test driven development_continuous_integration
haochenglee
 
PPTX
Test automation within a scrum process
Kushan Shalindra Amarasiri - Technical QE Specialist
 
ODP
Beyond Unit Testing
Søren Lund
 
What Is Cucumber?
QATestLab
 
Code review process with JetBrains UpSource
Oleksii Prohonnyi
 
Continous integration
Jeremy Wilken
 
Efficient mobile automation
Vitaly Tatarinov
 
Code Review Tool Evaluation
Kate Semizhon
 
Code Review
Tu Hoang
 
Continous Integration: A Case Study
Talentica Software
 
Robot framework - SAST Väst Q3
Anders Arnholm
 
Choosing the Best Open Source Test Automation Tool for You
Perfecto by Perforce
 
BDD with Cucumber
Knoldus Inc.
 
Test Driven Development
John Blanco
 
Test-Driven Development
Effective
 
Test-Driven Development
EffectiveUI
 
Elements of a Test Framework
SmartBear
 
Quality Built In @ Spotify
Andrii Dzynia
 
Test driven development_continuous_integration
haochenglee
 
Test automation within a scrum process
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Beyond Unit Testing
Søren Lund
 

Similar to Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding) (20)

PDF
Android testing part i
Kan-Han (John) Lu
 
PDF
Android Building, Testing and reversing
Enrique López Mañas
 
PDF
Guide to the jungle of testing frameworks
Tomáš Kypta
 
PPTX
Unit Testing in Android
Md Shamsul Arafin Mahtab
 
PDF
Cracking android app. Мокиенко Сергей
Alina Dolgikh
 
PDF
Testing and Building Android
Droidcon Berlin
 
PPTX
Test Driven Development on Android (Kotlin Kenya)
Danny Preussler
 
PDF
Oh so you test? - A guide to testing on Android from Unit to Mutation
Paul Blundell
 
PDF
A guide to Android automated testing
jotaemepereira
 
PPTX
Xam expertday
Codrina Merigo
 
PDF
Unit testing and Android
Tomáš Kypta
 
PDF
Testing Android
Marc Chung
 
PDF
Guide to the jungle of testing frameworks
Tomáš Kypta
 
PDF
Agile Android
Godfrey Nolan
 
PDF
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 
PDF
Building Maintainable Android Apps (DroidCon NYC 2014)
Kevin Schultz
 
PDF
Mobile Development - Unit and Automation Testing
Manuel Vicente Vivo
 
PDF
Unit Testing on Android - Droidcon Berlin 2015
Buşra Deniz, CSM
 
PPTX
Uber Mobility Meetup: Mobile Testing
Apple Chow
 
Android testing part i
Kan-Han (John) Lu
 
Android Building, Testing and reversing
Enrique López Mañas
 
Guide to the jungle of testing frameworks
Tomáš Kypta
 
Unit Testing in Android
Md Shamsul Arafin Mahtab
 
Cracking android app. Мокиенко Сергей
Alina Dolgikh
 
Testing and Building Android
Droidcon Berlin
 
Test Driven Development on Android (Kotlin Kenya)
Danny Preussler
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Paul Blundell
 
A guide to Android automated testing
jotaemepereira
 
Xam expertday
Codrina Merigo
 
Unit testing and Android
Tomáš Kypta
 
Testing Android
Marc Chung
 
Guide to the jungle of testing frameworks
Tomáš Kypta
 
Agile Android
Godfrey Nolan
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Kevin Schultz
 
Mobile Development - Unit and Automation Testing
Manuel Vicente Vivo
 
Unit Testing on Android - Droidcon Berlin 2015
Buşra Deniz, CSM
 
Uber Mobility Meetup: Mobile Testing
Apple Chow
 
Ad

More from DicodingEvent (20)

PDF
Developer Coaching #114.pdf
DicodingEvent
 
PDF
Ask Us Anything about Studi Independen Bersertifikat Kampus Merdeka X Dicodin...
DicodingEvent
 
PPTX
tantangan menjadi developer di abad 21
DicodingEvent
 
PDF
Mengenalkan augmented reality (ar) pada snapchat
DicodingEvent
 
PDF
Membangun Aplikasi Serverless di Platfrom AWS
DicodingEvent
 
PDF
IDCamp X Madrasah: Pengenalan Computational Thinking
DicodingEvent
 
PDF
Membuat Produk Digital Terbaik ala Startup Unicorn
DicodingEvent
 
PDF
TechTalk 2021: Peran IT Security dalam Penerapan DevOps
DicodingEvent
 
PDF
TechTalk 2021: Peningkatan Performa Software Delivery dengan CI/CD
DicodingEvent
 
PDF
Membuat Solusi Bermanfaat dengan Programming - Nur Rohman
DicodingEvent
 
PDF
Potensi karier menjadi ios developer di masa depan
DicodingEvent
 
PDF
Id camp x dicoding live : persiapan jadi software engineer hebat 101
DicodingEvent
 
PDF
Tips sukses berkarir sebagai developer dan programmer 2021
DicodingEvent
 
PPTX
Teknologi Baru Android di Google I/O 2021 - Andrew Kurniadi
DicodingEvent
 
PDF
Dicoding Developer Coaching #38: Android | 5 Library Android yang Patut Kamu ...
DicodingEvent
 
PDF
Dicoding Developer Coaching #37: Android | Kesalahan yang Sering Terjadi pada...
DicodingEvent
 
PDF
Pengantar Cloud Computing dengan AWS - Petra Novandi Barus
DicodingEvent
 
PDF
Dicoding Developer Coaching #36: Android | Pentingnya Performa pada Aplikasi ...
DicodingEvent
 
PDF
Dicoding Developer Coaching #34: Android | Modular Android App dengan Dynamic...
DicodingEvent
 
PDF
Dicoding Developer Coaching #35: Android | Setup Continuous Integration di An...
DicodingEvent
 
Developer Coaching #114.pdf
DicodingEvent
 
Ask Us Anything about Studi Independen Bersertifikat Kampus Merdeka X Dicodin...
DicodingEvent
 
tantangan menjadi developer di abad 21
DicodingEvent
 
Mengenalkan augmented reality (ar) pada snapchat
DicodingEvent
 
Membangun Aplikasi Serverless di Platfrom AWS
DicodingEvent
 
IDCamp X Madrasah: Pengenalan Computational Thinking
DicodingEvent
 
Membuat Produk Digital Terbaik ala Startup Unicorn
DicodingEvent
 
TechTalk 2021: Peran IT Security dalam Penerapan DevOps
DicodingEvent
 
TechTalk 2021: Peningkatan Performa Software Delivery dengan CI/CD
DicodingEvent
 
Membuat Solusi Bermanfaat dengan Programming - Nur Rohman
DicodingEvent
 
Potensi karier menjadi ios developer di masa depan
DicodingEvent
 
Id camp x dicoding live : persiapan jadi software engineer hebat 101
DicodingEvent
 
Tips sukses berkarir sebagai developer dan programmer 2021
DicodingEvent
 
Teknologi Baru Android di Google I/O 2021 - Andrew Kurniadi
DicodingEvent
 
Dicoding Developer Coaching #38: Android | 5 Library Android yang Patut Kamu ...
DicodingEvent
 
Dicoding Developer Coaching #37: Android | Kesalahan yang Sering Terjadi pada...
DicodingEvent
 
Pengantar Cloud Computing dengan AWS - Petra Novandi Barus
DicodingEvent
 
Dicoding Developer Coaching #36: Android | Pentingnya Performa pada Aplikasi ...
DicodingEvent
 
Dicoding Developer Coaching #34: Android | Modular Android App dengan Dynamic...
DicodingEvent
 
Dicoding Developer Coaching #35: Android | Setup Continuous Integration di An...
DicodingEvent
 
Ad

Recently uploaded (17)

PDF
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
PDF
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PPTX
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
PPTX
some leadership theories MBA management.pptx
rkseo19
 
PDF
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
PPTX
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
PDF
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
PPTX
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PPTX
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PDF
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
PDF
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
presentation on legal and regulatory action
raoharsh4122001
 
some leadership theories MBA management.pptx
rkseo19
 
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
AI presentation for everyone in every fields
dodinhkhai1
 
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
The Family Secret (essence of loveliness)
Favour Biodun
 
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 

Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dicoding)

  • 1. Gilang Ramadhan Academy Content Writer Dicoding Associate Android Developer Play with Testing on Android
  • 3. Specifications of the application Write the codes Test the application manually
  • 6. How to get started?
  • 9. ⬅, ➡, L1, L2, R1, R2, ⬆, ⬇, ⬅, ➡
  • 11. Follow best practices Built around modern design practices, Android Jetpack Libraries enable fewer crashes and less memory leaks with backwards-compatibility baked in. Eliminate boilerplate code Android Jetpack manages tedious activities like background tasks, navigation, and lifecycle management, so you can focus on what makes your app great. Reduce fragmentation Reduce complexity with libraries that work consistently across Android versions and devices. Why use Android Jetpack?
  • 12. Test
  • 16. “The percentage of your code that is executed by your tests” Test Coverage
  • 18. Test Driven Development The two cycles associated with iterative, test-driven development Source : Fundamentals of Testing
  • 19. is an application development method developed by testing. ● Writing Tests ● Running Tests ● Write down the Code ● Running Tests ● Refactor Code Test Driven Development
  • 20. ● More Productive ● Code is neater Safer ● Refactoring ● Minimizing Bug ● Documentation Advantages of using TDD
  • 22. ● Do not mock types you don’t own ● Don’t mock value objects ● Don’t mock everything ● Show love with your tests! Test Doubles
  • 26. REPLACE ME The important features of a testable architecture are: ● Each class should have a clearly defined purpose. ● Limit and be explicit about which classes know about other classes. ● Use constructor injection. ● Keep Android code out of the view model. Architecture Pattern
  • 27. 1. Local unit tests Located at module-name/src/test/java/. 2. Instrumented tests Located at module-name/src/androidTest/java/.
  • 28. 1. Run Toolbar. 2. Testing Toolbar. 3. Context Menu. 4. Test Status Icon. 5. Jump to Code.
  • 37. Let’s Try Together Source: ● Advanced Android in Kotlin 05.1: Testing Basics Updated ● Advanced Android in Kotlin 05.2: Introduction to Test Doubles and Dependency Injection ● Advanced Android in Kotlin 05.3: Survey of Testing Topics
  • 38. What we've covered: ● How to run tests from Android Studio. ● The difference between local (test) and instrumentation tests (androidTest). ● How to write local unit tests using JUnit and Hamcrest. ● Setting up ViewModel tests with the AndroidX Test Library. Testing Basics Updated
  • 39. What we've covered: ● What you want to test and your testing strategy determine the kinds of test you are going to implement for your app. Unit tests are focused and fast. Integration tests verify interaction between parts of your program. End-to-end tests verify features, have the highest fidelity, are often instrumented, and may take longer to run. ● The architecture of your app influences how hard it is to test. ● To isolate parts of your app for testing, you can use test doubles. A test double is a version of a class crafted specifically for testing. For example, you fake getting data from a database or the internet. ● Use dependency injection to replace a real class with a testing class, for example, a repository or a networking layer. ● Use instrumented testing (androidTest) to launch UI components. ● When you can't use constructor dependency injection, for example to launch a fragment, you can often use a service locator. The Service Locator pattern is an alternative to Dependency Injection. It involves creating a singleton class called the "Service Locator", whose purpose is to provide dependencies, both for the regular and test code. Introduction to Test Doubles and Dependency Injection
  • 40. What we've covered: ● A review of testing coroutines from previous lessons, including covering the usage of runBlocking versus runBlockingTest. ● How to test coroutines that use viewModelScope by using TestCoroutineDispatcher ● TestCoroutineDispatcher's ability to pauseDispatcher and resumeDispatcher to control coroutine execution ● Testing error handling by updating a fake ● Testing your data layer, including your DAO and local data source ● Using IdlingResource (and the CountingIldingResource subclass) to write end to end tests that both include long running code and work with the data binding library. ● Testing global app navigation in an end to end test. Survey of Testing Topics
  • 41. Advantages of Testing Testing also provides you with the following advantages: ● Rapid feedback on failures. ● Early failure detection in the development cycle. ● Safer code refactoring, letting you optimize code without worrying about regressions. ● Stable development velocity, helping you minimize technical debt.
  • 42. “Code without tests is bad code” Michael Feathers, Working Effectively with Legacy Code