Test-Driven Development in Android MVVM Architecture (Part 1-Basic Introduction)

Shehzab Ahammad
2 min readMay 25, 2020

--

Learn the basics of test-driven development, or TDD, and discover how to use TDD effectively when developing your Android apps!

Image from Pixabay

What is TDD?

TDD is a software development process. You can apply TDD wherever you practice software development, whether it’s iOS, Android, back-end, front-end, embedded, etc. It’s a process in which you write the tests that specify the code you’re going to write before you start writing any of the code.

Types of testing in Android:

  1. UNIT TESTING is a level of software testing where individual units/ components of the software are tested. The purpose is to validate that each unit of the software performs as designed. A unit is the smallest testable part of any software. It usually has one or a few inputs and usually a single output.
    Tools:
    1) JUnit
    2) Robolectric
  2. INSTRUMENTATION TEST is a test written by you or your team to specifically to test your app UI, using the Espresso and UI Automator 2.0 Android test frameworks.
    Tools:
    1) Espresso

I only mentioned the tools which we are going to use here 😉

Project Package Structure:

We can see, we have two packages that host our tests which are test and androidTest.

  • com.shehzabahammad.test_drivendevelopment
  • com.shehzabahammad.test_drivendevelopment (androidTest)
  • com.shehzabahammad.test_drivendevelopment (test)

Test: Unit tests are hosted in this folder. These tests run on JVM and do not require an Android device or emulator. This type of test has no access to any android framework-specific component like Context.

androidTest: All Instrumentation (Espresso) tests are hosted in this folder. These tests need a physical Android device or emulator to run.

What’s Next?

Next, we are going to dive into the implementation part. Check it out Part-2 by clicking here or in the below link.

Thank you for your time to read this article. If you like it please give me your clap 👏 , so others can find it too.

--

--