Home

Why TDD Can Be Good for Junior Software Engineer

By Taufiq on Apr 21, 2024
Thumbnail: TDD. Source: https://commons.wikimedia.org/wiki/File:Tdd-abstract.png

Test-Driven Development is an approach for doing software development, that was introduced by Kent Beck in the late 1990s.

TDD is

a software development process that driven by repetitive of: make a list of test, create a test, make it fail, write the code to make it pass, and refactor if needed.

To learn more about TDD, read article here or read the book Test-Driven Development by Example.

At first sight, it looks like that we need some extra effort to write the test first before writing the actual code. But, for me, it can help junior software engineers to learn and understand the software development process better.

Why? Let me explain.

It started when I was a software engineer at a startup company, our team was not doing test at all. We just write the code, have some code review, then push to production. It was fast and fun at first, but as the codebase grows, it becomes harder to maintain, refactor existing features and add new one.

Our team started to have a lot of bugs as well, here and there, even it is kinda distrubt the current sprint development. When we do retropection, we discuss about how we can solve this problem. Then, one of our team member suggest to start doing TDD. And at that time, was me, who was assigned to learn and implement TDD in our team.

Then, I started to learn TDD by reading books, articles, and try it myself. After that process of learning, I create a workshop for our team to explain what is TDD, how to do it, and how maybe it can help us to solve our problem.

But here, I am not going to talk about how TDD implemented in our team back then.

It just that, after doing development using TDD mindset for sometimes, I think, maybe TDD can help junior to be better software engineer.

1. Be the user

In the first stage of TDD, we need to list out all of the test cases that we need to cover.

This is where junior software engineer can learn to think from the user perspective. What the user wants, what the user needs, and how the user will use the feature. It is a time, that we think about the user before even writing the code.

In the end, the implication is that we can cover as many as possible test cases that can be happened in the real world from user perspective. First, we can cover the thing that maybe we don’t think about it before. Second, maybe we prevent some bugs that can be happened in the future.

2. Write maintainable code

One of the TDD principles is to write the simplest code that can make the test pass.

We make the test fail at first, then at minimum effort, we write the code to make it pass. Then we think, do we can refactor it to make it better? If yes, then we refactor it. Repeat the process until we are satisfied with the code.

For me, it can make me mindful when writing the code, because I am being force to write the simplest code and after it, I re-read the code and think, can I make it better? Can I make it more readable? Can I make it more maintainable?

3. Test

One of most important part of TDD is the test itself.

There are some benefits we can get from writing the test:

  • Automatically test the code anytime
  • Document the code
  • Prevent regression

Then how it can help junior?

Let me clear it up first, TDD is not a silver bullet to do software development. You can use TDD and make a good software. And then you also can make a good software without using TDD.

For senior, you maybe already have a lot of experience, you know what to do, you know how to do it, and you know what will be the impact if you do it.

But for junior, it is different. They still learning things, they still searching for the best practice, they still searching for the best way to do development.

TDD is a discipline that can help junior to learn and understand the software development process better. It enforce them to think from the user perspective, write maintainable code, and test the code along the way. The most important thing is, at least, with the test we can minimize the bugs that can be happened. It good for business, for the user and for the developer itself.

And maybe if they already understand the software development process better, they can choose to use TDD or not. But at least, they already know what is TDD, how to do it, and how it can help the development.

So yeah,

It just that I think

TDD is a good discipline for junior software engineer to create a good software.

© Copyright 2024 by Taufiq Septryana | Software Engineer. Built with ♥ by CreativeDesignsGuru.