Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I tend to think that the most valuable tests are on the exact level of when something gets used by multiple consumers.

So shared functions get unit tested, but if there is a non shared function that gets triggered only from few layers up via user click, it is better to simulate that click and assert accordingly. However the exceptions are when the input can have tons of different permutations, when unit test might just become more optimal then.



Yes exactly. If you're writing a library, unit tests are likely a great investment. Your "customers" are using the things you are testing.

If you're writing an API, your customers are calling the endpoints. Very important they behave properly on happy path and fail appropriately when they should (permissions / security especially)

(I also ensure tests in the service/dao layer to protect developers from footguns and/or more "unexpected" behavior, but I'd argue the API layer is generally more important)

If you're writing a react app, playwright is very important (and using it properly / acting like a real user) as your customers are interacting with it via a browser.

Though the larger the codebase/ when you start having reusable components, the better tested they are, the less will go wrong in the future as an unfamiliar developer will inevitably hold it wrong.




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

Search: