Hacker News new | past | comments | ask | show | jobs | submit login

Unit tests show expected input and output of a function.

In code that was written without tests, inputs/outputs end up being surprisingly far more spread out than you might think. One of the function inputs might be a struct with 5 members, but the function itself only uses one of those members 50 lines in. If it's OOP, one of the inputs might be a member variable that's set elsewhere, and same for the outputs.

A unit test shows the reader what information is needed for the function and what it produces, without having to read the full implementation.

Also, when you write it, you end up discovering things like what I mentioned above, and then you end up refactoring it to make more sense.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: