Hacker News new | ask | show | jobs
by goto11 1624 days ago
What is the purpose of automated testing? Is it to ensure the code works correctly or is it to "run fast"?
2 comments

To be able to say to your bosses that you have 100% code coverage.

No, I agree. Hitting the database is slower but not that much slower (at least if you use PostgreSQL and do rollback after every test). And since the goal is correctness I think that this performance hit is small enough to be worth taking.

> to ensure the code works correctly

It's to ensure the code works correctly and indicate where the problem is, whenever it doesn't work correctly. Querying a live database during unit tests fails on both accounts. It doesn't tell you whether or not the code works correctly - it tells you either that the code didn't work correctly or that the database wasn't available at the time the test ran.

Well both things are problems which is nice to know about so you can fix them. Certainly better than not knowing about either problem.