Test Driven Development: Making sure your code is doesn’t sh*t itself to much.

What is Test Driven Development?

Source: What is Test Driven Development (TDD)? Tutorial with Example (guru99.com)

How to TDD?

  1. Create or add some tests
Here I wrote some tests for “Lampiran” model
Here I try and run the tests. The tests failed because I haven’t implemented “Lampiran” model yet.
Here I implement Lampiran Model according to needs.
After I implemented the models, the tests are now passed!
Here I write the next tests for the next functionality, in this test I plan to develop a serializer for the model.

An Example of Implementing TDD

  1. Pick a functionality/requirement that needs to be met.
Example of Commit message for [RED]
Example of commit message for [GREEN]
Example of commit message

Why you should use TDD in almost any project?

  1. Minimizes bugs and errors in the program/application
    Usually TDD results in more tests being written because we are much more thorough about the code we write. More tests means more code coverage and less likely to come across a bug that isn’t covered in the code.
  2. More focused coding
    From the process I explained earlier, when writing a test we pick a functionality beforehand. So during an iteration, we are more focused on finishing that functionality and less like to wander off to other functionalities that also need to be met.
  3. Modularity
    Because of the “pick one functionality” mindset from this cycle, the code we write tends to become less dependent on other code (or modular). This helps prevent programmers from breaking the program when writing the program.
  4. Safe refactoring
    When refactoring, we have a safety net of tests to ensure when we make a mistake while refactoring, we can catch the mistake after running the tests. This also prevents programmers from accidently breaking the program when refactoring something. Preventing any mistakes like the ones I made in my initial story.
  5. Tidier Code
    Because TDD causes the code to become more modular, the code we write tends to be more tidier as well.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Goodbye Jenkins (Part 2): Give Flight to your CD with Drone Control

Cloud Native Application Architecture And Why They Matters

Building a React Native Mobile App with AWS Amplify and Expo

Migration of Objects — Valuesets, Lookups, Fast Formula, Payroll Flows from one POD to another

What’s New In Flutter 2 ?

How To Queue Management The Planet Using Just Your Blog

SQL bits & bytes-Best Practices

How to trace Goroutine Leak ?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abdurrafi Arief

Abdurrafi Arief

More from Medium

Six Key Questions a Software Engineer Answers When Asking for Help

Code design, why?

The Singleton Design Pattern

design pattern

A new year Journey: Two Aim One Book — Clean Code