Join Alexander Zanfir for an in-depth discussion in this video What is testing and test first?, part of Test-Driven Development with Node.js.
- In this chapter, we'll take everything we learned and put it all together in one final app, but we'll be creating it with a process called Test First. But before we continue, what is testing and Test First? First, let's talk about a typical workflow without programmatic testing. You have some planned app specifications, some behaviors you need to program, and once it's complete, then you or someone else will try your app and might find a bug today or maybe a year from now. Validating the app functions as expected with this process requires some sort of human element and the process might be slow, and it also might miss some things.
With programmatic testing, on the other hand, we will write many applications that check just a small part of your program. Think of it as a program that checks to make sure another program is working normally. When these tests are very small, small enough to check just one feature or some sort of isolated functionality of the app, these are called unit tests. On the other hand, when these tests are much bigger, and they test multiple features working together, or one system communicating with another or interacting with it, these tests are called integration tests.
So we know tests are just small little programs we write to test functionality of our main application. But what about Test First? If you have never programmed with Test First, such as in TTD, which stands for Test-Driven Development, or BDD, which stands for Behavior-Driven Development, this will be a game-changer for you. This will change your programming workflow paradigm drastically. With Test First, you write absolutely no functional code until you are able to express a feature or program specification in the form of a test.
So you start with the code that tests what you are about to program, and then you run your test and hope that it fails. And obviously, since you have no written code to make the test pass, it will fail. This now means you are ready to start programming functionality in your actual app. On the other hand, if you haven't written any functional code for your app and the test is passing, that means something is wrong with the test. That's why this is a necessary step you must not skip. Once the test fails, it's now time to implement the feature in our actual app.
Then we will run our test and when the test passes, you can move on to the next test and feature, and repeat this process over and over.