DEV Community

Mohmed Ishak
Mohmed Ishak

Posted on • Updated on

TDD (Test Driven Development) For People Who Hate Reading

Alt Text

What's TDD?

Stands for Test Driven Development. It is when you write a test first in a development which would "drive" the development of any feature. Before that let's take a look at a sample test. A test is just additional codes that test your actual codes.

describe("greet", () => {
  it("should return the greeting message", () => {
    const result = myLibrary.greet("Ishak");
Enter fullscreen mode Exit fullscreen mode

If you've never written a test before, in the above snippet, I'm invoking a function called greet() in an imaginary library by me called myLibrary. Then, I'm asserting the result to match a regular expression such that my name is included in the greeting message, for example "Good morning, Ishak! Have a great day". As you can see, writing test is not difficult because it's not meant to be difficult. Writing test cases are super straightforward.

Do You Need TDD?

You may develop your application first and then write tests, but with more failing tests, come greater stress. Not only that, most of the developers wouldn't be motivated enough to write "intangible" tests after the development of actual application. In contrast, if you develop application with TDD, not only you don't have to write boring tests after developing an application, but almost every feature will have test case(s) behind it whether you like it or not because that's the nature of TDD.

When Do You Need TDD?

For small application that you develop without thinking about scalability and other issues, I wouldn't suggest TDD because it's time consuming and pretty unnecessary. However, to develop large-scale application, you need TDD for all the great benefits it offers such as eliminating low motivation to write tests, super high test coverage for your codebase, and simply allowing you to build projects with strong foundation.

Top comments (0)