How long did it take to manually test the application in the previous exercise? If you repeated the process 100 times, how often do you think you would make a mistake?
In a company, someone must be paid to do that work, so every hour of manual testing has a cost. The cost of testing can be reduced and the quality can be improved with automated testing.
Automated testing is the use of software to control the execution of tests and the comparison of actual behavior to expected behavior. All the testing you just did (and more) could be performed by a computer program.
Compared to manual testing, automated testing is
- Faster: it tests more of your product in less time.
- More reliable: it’s less prone to error than a human is .
- Maintainable: you can review, edit, and extend a collection of tests.
Rather than hire a testing team at the end of development, professional developers can run their automated tests after every change. The workflow might look like this:
- Write code and corresponding tests
- Enter a command into a terminal to run tests
- If the app behaves as intended, all tests should pass. Development is complete.
- If it does not behave as intended, at least one test should fail. Fix code and return to step 2.
This web app is set up with automated tests. Run them by entering
npm test in the terminal.
Wait for the test output to appear.
The tests align with the expected behaviors in the previous exercise. Which method caught more bugs? Which was faster?