Back to blog
My Experience with Test Driven Development
Aug 28, 20223 min read

My Experience with Test Driven Development

This blog talks about my experience diving into TDD

Rizwan Memon

Software Engineering is not easy, like building a bridge to spec and just forgetting about it. Software evolves with time, and your requirements change with many other things. It's not a build it once and forget about it for years thing.

One thing I see most junior developers throw out of the window is testing. Sometimes going years of writing code without ever writing tests. I am also guilty of it. But when I started TDD, I realised how much I was missing out on when not writing tests.

Why Testing?

Have you ever been in a situation where you are tackling the same JIRA ticket for weeks? Every time you think you got it just right and then the next day your QAs assign it back to you. And this basketball game never ends. If that sounds familiar, I really think you should give TDD a shot :)

Oh God Please! No No.

What are some of the benefits I noticed when following TDD

  • You are confident that your code will work and does not add any major bugs in some different parts of the application.
  • Adds a sense of ownership. You break something you fix it.
  • Helps with writing better code. To write good tests, you have to follow certain patterns. Example: You can't make API calls directly inside a component because the API might return different data over time which will lead to a brittle test.
  • Saves a lot of time overall in the long run.

Okay, now you are convinced to start writing your first test. But wait I want to share something before you do that.

  • Try to write tests first, or at least go back periodically and add them. One of the biggest mistakes we made, was not adding tests early. We wrote a lot of production code which made writing tests even harder. Mocking so many dependencies all at the same time is very hard. Follow the Red-Green-Refactor approach.
  • It is very important to write good tests, having bad tests are as good as not having tests at all. If you can't rely on your tests it's better to not have them in the first place.
  • It is gonna take a while to write good tests, you are gonna be stuck, and you might have to spend more time on tests than writing production code. But this will get better with time. Take your time and be patient.

Now that you are ready to start learning more about TDD and write your first tests. Consider subscribing to the newsletter I periodically share my experiences over there like these. Also building cool challenging things like this animated bulb I made with CSS :)

import { test, expect } from '@playwright/test'

const { describe } = test

describe('Test Driven Development', () => {
  test('should be subscribed to the newsletter', async ({ page }) => {
    await page.goto('https://rizwan-memon.vercel.app/')
    const user = getUser()
    await expect(user).toBeSubscribed()
  })
})

TDD is something I have been also playing with and not something I am a pro at. Still, if you are struggling with where to begin shoot me a DM over at Twitter. I would recommend you to read Clean Code Chapter 09: Testing and if you specifically looking for a React video watch this.

More posts

All posts
Building Frontend Observability
ObservabilityFrontend
Feb 1, 20268 min read

Building Frontend Observability

A deep dive into building an o11y platform for frontend performance, errors, and user sessions - from MVP to production.

Rizwan MemonRead