Hacker News new | ask | show | jobs
by IshKebab 919 days ago
IMHO UI tests are just too difficult to be worth bothering with in most situations.

Maybe AI will change that. But for now I think dev time is generally better invested in other ways of making code work properly, or just fixing bugs that have already been reported.

I know that sounds heretical.

1 comments

> IMHO UI tests are just too difficult to be worth bothering with in most situations.

Yes, that's because you're doing them wrong.

Don't mess around with the "golden master" testing (edit: seems the frontend ecosystem call that "Snapshot Testing" actually, but it's the same) you see bunch of projects do, that compare the old DOM vs the new DOM you accept/deny changes based on component render output. That's a waste of time and won't actually prevent bugs.

Instead, extract the logic-heavy parts out from your components, then put those under unit tests, like any other code you write.

Boom, easy to maintain, verifies your implementation and makes your UI easier and faster to refactor and build in the first place.

But then those are by definition not UI tests.

In an ideal world one might argue that everything testing-worthy (ie. the logic-heavy parts) is already factored out from the UI components but getting to that point either needs a good amount of foresight and discipline or some a lot of refactoring which is difficult to trust without existing UI tests...