Book Image

Modern Android 13 Development Cookbook

By : Madona S. Wambua
5 (1)
Book Image

Modern Android 13 Development Cookbook

5 (1)
By: Madona S. Wambua

Overview of this book

Android is a powerful operating system widely used in various devices, phones, TVs, wearables, automobiles, and more. This Android cookbook will teach you how to leverage the latest Android development technologies for creating incredible applications while making effective use of popular Jetpack libraries. You’ll also learn which critical principles to consider when developing Android apps. The book begins with recipes to get you started with the declarative UI framework, Jetpack Compose, and help you with handling UI states, Navigation, Hilt, Room, Wear OS, and more as you learn what's new in modern Android development. Subsequent chapters will focus on developing apps for large screens, leveraging Jetpack’s WorkManager, managing graphic user interface alerts, and tips and tricks within Android studio. Throughout the book, you'll also see testing being implemented for enhancing Android development, and gain insights into harnessing the integrated development environment of Android studio. Finally, you’ll discover best practices for robust modern app development. By the end of this book, you’ll be able to build an Android application using the Kotlin programming language and the newest modern Android development technologies, resulting in highly efficient applications.
Table of Contents (15 chapters)

Writing tests for our DataStore instance

Writing tests is crucial in Android development, and in this recipe, we will write some tests for our DataStore instance. To test our DataStore instance or any DataStore instance, we first need to have instrumentation testing set up since we will be reading and writing in actual files (DataStore), and it is vital to verify that accurate updates are being made.

How to do it…

We will start by creating a simple unit test to test our view model function:

  1. In our unit test folder, create a new folder and call it test, and inside it, go ahead and create a new class called TaskViewModelTest:
      class TaskViewModelTest {}
  2. Next, we will need to add some testing dependencies:
    testImplementation "io.mockk:mockk:1.13.3"
    androidTestImplementation "io.mockk:mockk-android:1.13.3"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2"
  3. Now that we have added the required dependencies...