Manual testing is an illusion of safety. Code evolves, and manual tests are forgotten. Automated testing is the bedrock of professional engineering.
1The Fear of Deployment
When a codebase grows to 50,000 lines of code, changing one file can inadvertently break another file entirely. This is called a 'Regression'. If you do not have automated tests, the only way to catch a regression is if a user complains that your app is broken. Automated tests are scripts that run every time you save a file. If your new code breaks an old feature, the test fails instantly, preventing you from deploying broken code to production.
async function execute() {
// See concept above
}
2Headless Network Requests
To test an API, you could literally run node server.js to start your app on port 3000, and then write a script that uses fetch() to hit localhost:3000. This is slow and prone to port conflicts. The supertest library bypasses the network entirely. It takes your Express app object and directly invokes the routing logic in memory. This allows you to run 500 API tests in just 2 seconds.
async function execute() {
// See concept above
}
3Database Isolation
When writing Integration Tests that hit the database, you must NEVER run tests against your Production database! Your test will delete real users. You must configure a separate 'Test Database'. Furthermore, tests should be 'Idempotent' (repeatable). Before every test run, you should automatically wipe the test database clean and insert fresh 'seed' data, ensuring that Test A doesn't accidentally affect the outcome of Test B.
async function execute() {
// See concept above
}
