Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Kotlin for Android 14

You're reading from  Mastering Kotlin for Android 14

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781837631711
Pages 370 pages
Edition 1st Edition
Languages
Author (1):
Harun Wangereka Harun Wangereka
Profile icon Harun Wangereka

Table of Contents (22) Chapters

Preface 1. Part 1: Building Your App
2. Chapter 1: Get Started with Kotlin Android Development 3. Chapter 2: Creating Your First Android App 4. Chapter 3: Jetpack Compose Layout Basics 5. Chapter 4: Design with Material Design 3 6. Part 2: Using Advanced Features
7. Chapter 5: Architect Your App 8. Chapter 6: Network Calls with Kotlin Coroutines 9. Chapter 7: Navigating within Your App 10. Chapter 8: Persisting Data Locally and Doing Background Work 11. Chapter 9: Runtime Permissions 12. Part 3: Code Analysis and Tests
13. Chapter 10: Debugging Your App 14. Chapter 11: Enhancing Code Quality 15. Chapter 12: Testing Your App 16. Part 4: Publishing Your App
17. Chapter 13: Publishing Your App 18. Chapter 14: Continuous Integration and Continuous Deployment 19. Chapter 15: Improving Your App 20. Index 21. Other Books You May Enjoy

Testing the network and database layers

In this section, we are going to learn how to write tests for our network and database layers step by step.

Testing the network layer

To test our network layer, we will write unit tests. However, since we are using Retrofit to make our network requests, we will use MockWebServer to mock our network requests. The MockWebServer is a library that allows us to mock our network requests. Let us start by setting up the test dependencies in our version catalog:

  1. Open the libs.version.toml file and add the following versions in the versions section:
    mockWebServer = "5.0.0-alpha.2"
    coroutinesTest = "1.7.3"
    truth = "1.1.5"

    We are setting up the versions for mockWebServer, coroutinesTest, and truth.

  2. Next, in the libraries section, add the following:
    test-mock-webserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "mockWebServer" }
    test-coroutines = { module = "org.jetbrains...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}