Are unit tests worth it?


In the realm of software, unit tests are like unsung heroes. They quietly play a crucial role, ensuring that each part of the code, or each “atomic unit,” behaves as it should. 

Let’s dive a bit deeper into this concept, keeping things simple and relatable. Imagine we’re talking about a car.

Unit Tests: Checking the Basics

Consider a car. It’s made up of various parts, each with a specific function. In unit tests, we focus on these individual parts separately. We’re not concerned with how they interact, but rather, we want to make sure each part is doing its job correctly.

For instance, we might have two separate unit tests for a car:

  • One that checks if the engine is working properly.
  • Another that ensures the window fits perfectly in the door.

Integration Tests: The Interaction Game

Moving on to integration tests, this is where we see how well the different parts play together.

Sticking with our car analogy, an integration test might check whether you can smoothly open the window while the engine is running

It’s like making sure the various components of the car cooperate well, ensuring a smooth ride (or in our case, smooth code execution).

Upgrades and Adjustments: The Test Continues

Imagine wanting to upgrade the engine of the car. Naturally, this change means that new unit tests will be necessary to ensure the revamped engine’s behavior is up to mark. 

However, the unit tests for the window remain unchanged; they continue to ensure that the window fits and operates as it should.

When Tests Fail: Unveiling Issues
If an integration test fails, it’s a clear red flag—something’s off. It’s pretty straightforward. 

But let’s consider a scenario where a unit test, say for the window, crashes unexpectedly. 

This could signal a significant issue, possibly pointing towards a problem like tight coupling in the code.

The analogy might seem a bit abstract when applied to a car, but in the software world, weird and unexpected things happen quite frequently. Understanding unit and integration tests, and their significance, helps in navigating through the complexities and weirdness that software development often presents.


To keep certain standards of the software, we need to implement all layers of the test pyramid.

Join AndroidPro newsletter & get roadmap for Android devs

👉 Architecture
👉 Testing
👉 Compose
👉 projects to learn from
… in a single document

Read more:

  • #kotlinDevChallenge – 10

    #kotlinDevChallenge – 10

    Implement a function that sums the first 5 even numbers from each of three given integer Flows and returns their total sum. Properly handle…

  • #kotlinDevChallenge – 9

    #kotlinDevChallenge – 9

    Write a function that takes a list of lists of integers and returns a single list containing all unique elements. Ensure that the resulting…

  • #kotlinDevChallenge – 8

    #kotlinDevChallenge – 8

    data class A is given. We create an instance of this class and then call the .copy() function. What will be printed out? Mark…