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

Advanced Error Handling in Swift 5

Spark Coalesce and Repartition

Scrum Master interview: How a mind teaser can say a lot about the mindset

Deploy our backend (spring-boot) application using Azure Web App Service

How to Fix Discord Overlay Flickering?

How to Set Up Ambassador API Gateway with ALB Ingress Controller

Building a SQL Engine Infrastructure at QuintoAndar

Applying JoltTransform on JSON Object Array and fetching specific fields

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

CRUD is simple until it’s not

Refactoring Summaries

Scaling Environments Up & Down

Principle of Least Astonishment