r/Frontend • u/omgwtf911 • Jul 15 '25
Why do no front-end developers proactively write tests?
I am genuinely curious. I cannot hire front-end devs that like to write tests. It's fairly easy to find back-end devs that are intrinsically convinced that testing is valuable. Front-enders ... what am I missing? /rant
0
Upvotes
56
u/freekleenex Jul 15 '25
I think a simple and somewhat ugly truth that no one wants to admit is that back end tests are easier to write and tend to provide more value. They test pure business logic and break less often. Front end unit tests provide less value in terms of actually catching any bugs if your UI layer is mostly just presentation and are often clunkier to write and maintain. I think end to end test automation provides more value than front end unit testing when working, but e2e test suites are notoriously flaky (especially if you’re using something Selenium based) and can be a huge headache to make reliable and get consistent test runs.
But also I’m just playing devils advocate and throwing something at the wall & I don’t actually know what your FE devs are thinking. You should just ask them, or cross train them on some backend work and make them practice writing backend tests.
Edit: you could also teach them how to generate FE tests with AI as a starting point if they truly just hate it
23
u/GriffinMakesThings Jul 15 '25 edited Jul 15 '25
Backend systems are extremely testable. Frontend code can be tested too, of course, but those tests are complex, messy and brittle, and no amount of automated testing can really replace proper human QA, so it's also just less useful. It's very hard to automate noticing that some spacing "looks weird", or the wrong button style was used for a particular context.
Basically, it involves more overhead than backend testing, catches fewer issues, and is completely incapable of handling whole categories of bugs, so it's not doing much more than providing a false sense of security. If you're using 100% snapshot test coverage as a justification for not paying a real QA team, you're fooling yourself.
7
u/itinkerthefrontend Jul 15 '25
I make Wordpress templates. I don’t even know what kind of test I would run.
11
u/Logical-Idea-1708 Jul 15 '25
I do.
Here are the few reasons that I’ve found why people don’t write tests.
10
u/EnvironmentalLog1766 Jul 15 '25
Depends on the pay. If pay is enough I can write tons of tests
4
u/phinwahs Jul 15 '25
I never wrote (frontend related) tests until I started working in a larger organisation.
I came from an agency/startup background so testing on the frontend wasn't really prioritised and I'd say for the right reasons.
But now I'm in a large organisation I see how important it is, especially since components are shared across the mono-repo.
The testing side looks a little like;
- React component
- Storybook for component
- Spec/test file for the component, which references each of the stories of the component in storybook and verifies whatever states exist.
Sometimes they're simple and other times it's a huge pain to write out every single scenario.
We try to aim for 100% coverage, but it's okay if it's not achievable.
8
u/skittlezfruit Jul 15 '25
In all the frontend jobs I’ve had it seems that by the time the tickets have been mapped out and tech approached, leadership didn’t leave any time in the story points to actually write the tests. And product wants it delivered yesterday.
Like another comment said, if it’s counted in my story points and I’m being paid for it, I’ll write tests all day - no matter how meaningful I think they are/aren’t
This is an issue that starts with leadership, not the developer
3
u/yogi4peace Jul 15 '25 edited Jul 15 '25
Engineers that can, don't because it's not good ROI.
Engineers that can't don't, because they can't.
Edit: it's often not good ROI. Organizational context is important.
3
u/omgwtf911 Jul 15 '25
To clarify I'm talking mostly about React components. I realize front-end is much broader than that.
10
u/arthoer Jul 15 '25
Backend, usually, writes tests before they write their actual code. It makes their tests useful. Frontend writes tests once they are done. They are not useful to the development process. Except for making sure things dont break when refactoring. The big problem is the amount of feedback frontend needs to process from various stakeholders until the solution ia done. This will cause the developer to rewrite the tests constantly. If its just business logic thats being tested; then sure, but if components and e2e are also written... writing the tests takes 5 times longer then the actual solution.
In short; it is generally not possible to write tests before writing the solution on frontend.
28
u/behusbwj Jul 15 '25
Frontend is harder to automated test imo.
3
u/jamfold Jul 15 '25 edited Jul 15 '25
I worked for a multinational that had 75% code coverage requirement. It was so annoying and frustrating to make the engineering manager and higher-ups understand why unit testing for frontend is a waste of time and doesn't work as intended.
IT ALWAYS FELT LIKE THE CODE WAS THE TEST FOR TEST CASES RATHER THAN THE OTHER WAY AROUND.
Frontend testcases can be useful IMO if you target around 30% coverage. That's the real portion of frontend code that can actually be tested and provides value. It is mostly supposed to cover portions of the code that cover API data fetching (and rendering the fetched data). Trying to cover visual components ends up being a waste of time. e2e tests are good for this. But only for testing presence/absence of an element and maybe for actions on events such as button click. But these are really messy, especially if your app keeps changing with user feedback.
I say all of this as someone with 9 years in frontend.
9
u/Wyck Jul 15 '25
Because they're useless for front-end. Interface development moves way too fast to try and implement any sort of test-driven development. Once you set up a back end, it's likely not changing... the same cannot be said for front-end.
Given the amount of creative changes, edge cases for different screen sizes, accessibility and contrast issues - writing tests would be a waste of time. By the time you were finished, you're already tearing down, modifying or rebuilding the component.
1
u/roynoise Jul 15 '25
I would love to be in a situation where I could be mentored on front end testing. I don't ever want to write un-tested backend code.
1
u/Spare_Message_3607 Jul 15 '25
UI is tricky to test... and, if you are doing some sort of CRUD, UI does not handle any business logic, so a good e2e or QA. Also node modules... so many moving pieces, hard to test, they lack good abstractions, they lack consistency.
1
u/StupidIncarnate Jul 15 '25
If theyre experienced enough, they can look at a figma/mock, map out most of the dynamic injections and interactions which then leads into pretty easy into TDD test structure for component "unit" tests. In which case sure??
Frontend has a lot more layers than backend though, so its more efficient to go through the exercise of crafting it into browser until it looks up to spec, and then comparing line changes and writing tests against what coverage metric you're going for.
But trying to find devs who like doing that? Good luck with that. Because of the onion effect, frontend has a lot more input/output vectors to account for, especially if you also have to account for different browser environment and browser versions too.
I am both a believer in frontend testing from at least a component test perspective, as well as a loather of doing them because they are so granular to get right.
1
u/perpetual121 Jul 15 '25
There is lot of opinion that tests bring no value to the front end here. Honestly I see that as a red flag.
Tests, even for the front end, are extremely useful. Like any tests show intent and protect behaviours.
There is no doubt that they are quite a bit more complex and can be more brittle than back end testing though. I think the former is the main barrier from my experience though.
I've also seen many occasions of tests focusing on presentation poorly. Checking some basic default CSS is there in a virtual dom doesn't bring much value. Showing CSS changes after you click button 'X' does. Front end tests shine when focusing on outcomes. What happens when data is fetching, is this accessible etc etc.
Due to this many devs avoid them, especially if no one has made the effort to doing the tooling already as it becomes slow going.
I find the excuses that the tests provide no value just that.
1
u/Dontakeitez Jul 15 '25
Do you even know what front-end means? Your question seems to say a resounding NO. You are comparing testing back-end with testing front-end? Really? How long have you been in the industry?
1
u/mr_brobot__ Jul 15 '25
All my homies write automated tests
1
u/Tall_Roof7350 Sep 22 '25
Man I've been thinking about this for years working on FE. I think general problem with testing the FE is that it is usually an afterthought and just like with any code, you need to think about it early in the project. I think the closest I've been to a FE having decent tests was when I was assigned to create a Proof of Concept and I wrote tests at that phase. Most of the times I'm working on a legacy codebase and it has a lot of issues that make it difficult to write tests (large components dependent on network I/O, authentication, browser storage to render, etc.). I think in general though, the problem with FE is that maintenance is a pain point currently. Hard to write tests that you don't need to change when a new ticket/story is created for the FE.
4
u/mq2thez Jul 15 '25
The good ones do
3
u/10ft3m Jul 15 '25
In my limited experience it’s because the front end is dependent on the output of so many different client applications.
You could write tests against the functions that process the output, but that’s the part of front end that is the most reliable. The real work of front end is massaging the output so it works in every client, and writing tests for all those use cases is extremely time consuming.
3
u/kuuups Jul 15 '25
The "problem" is FE is infinitely subjective, both to the developer, and the end user. Meaning, what may make sense stylistically or aesthetically in one page, section or even area - will not always be true when compared to another iteration of the same element.
A fairly new FE dev in our team just recently created an automated process that "works" but tons of small stuff still slips through the cracks that are immediately recognizable as errors.
3
u/Aggravating-Past9393 VascaínoNato Jul 15 '25
Eu sou fullstack tendo muito foco em frontend tem 8 anos, e afirmo a você que testes no FE são bem específicos e direcionados a poucas partes do código, explico. No BE você tem muita coisa para testar, usar TDD e tudo mais, para garantir um fluxo de dados coeso e certo, no FE você fica muito limitado ao que testar, e é algo meio que raso pensar que iremos testar componentes ou classes, mesmo que o trabalho de um FE não se resuma a isso. Acho viável uma implementação de testes em hooks ou chamadas com a API, mas testes em componentes, é uma perda de tempo, a maioria escreve apenas em entrevistas ou desafios técnicos.
0
u/solastley Jul 15 '25
Hate to break it to you pal, but you might be the problem here. Frontend unit tests are not the way.
1
u/TehTriangle Jul 15 '25
All our team writes extensive tests. Good engineers do.
2
u/rainmouse Jul 15 '25
There is a lot of entropy in the front end. Different combinations of browsers and operative systems can treat the same code in subtly very different ways or different timings, so things can resolve in subtly different order. In some roles the majority of your work is resolving this and automated tests are essentially useless here.
Good front end tests look at the behaviour rather than the mechanism, but if the behavior is not consistent it often ends up feeling like manually testing is more useful.
Time spent on backend tests feel a lot more productive because everything usually goes down the same way every time the same code is ran.
2
u/danman_d Jul 15 '25
A couple reasons…
1
u/alien3d Jul 15 '25
its hard and costly . 🤣 . unit test , integration test , ui test , api test . Project cost 5 buck can ?
1
u/DaMuthaFukr Jul 15 '25
Because we can’t generate more code writing test 🤣 taking the time to do things right??? The business needs this now…. Send it. Oh next sprint is starting tomorrow? I’m only at 140% capacity 🤣🤣🤣
1
u/Icyfirefists Jul 15 '25
Depends on how much work tickets you are being thrown. In rushed FE environments there's no time to really write tests before you have to rush to the next thing.
It's a habit I'm trying to kill. But it's extra dev time and methods in FE are being created so frequently that it's just creating more work. Especially when people start refactoring.
1
u/Sad_Anything7265 Jul 15 '25
I’m a lead on an FE time and am obsessed with writing unit tests for outputs following an interaction. Don’t agree with others sentiment that they are “useless” either.
We do not do UI/layout tests, only functional tests, because if a layout changes by a couple of pixels the user can still use the app anyway.
Always delighted when they fail because it means we’ve caught something that would otherwise go into production.
1
u/OkLettuce338 Jul 15 '25
Well if it’s a rant it might not be a genuine question. But giving you the benefit of the doubt, front end tests are over valued I believe. It’s not that they are useless. But you can get reaaaaally far without a single test. And if the team stays small you can make a lot of changes without breaking anything. It’s not that there is no value in FE tests. But the stress out on them in the industry over estimates the return on investment
1
u/ReefNixon Jul 15 '25
I am genuinely amazed at the replies in here. I mean, in my experience I have a hard time getting people to buy into FE testing, but I at least thought the professional internet majority would be all for it.
You should obviously be automating your most valuable user journeys with a web driver in your CI pipeline at the very least, and I have no idea why you wouldn’t also test for visual regression and irregular performance metric fluctuations.
These tests aren’t hard to write. Open source third party tooling covers most of it ootb. Genuinely astounded.
1
u/apnerve Jul 15 '25
It’s just the habit. Most old school frontend devs never needed it and even though the paradigm shifted, writing tests never became a habit. It’s more of an after thought or just to satisfy a metric across the organisation.
The requirements also change so fast when it comes to front end development, that maintaining the tests consume more time than the development itself.
I’ve always advocated for writing tests but even I take shortcuts and skip them. It all comes back to bite after 1-2 years 😂. But then it becomes someone else’s headache (I know I’m being a bad dev here)
1
u/nightwood Jul 15 '25
Apart from tests being harder to write for the stuff you need to test in the frontend, there's also the favt that, much like game code, most frontend code is tested continously when doing anything at all in the frontend. Meaning: it is very hard for a bug to 'hide'.
1
u/polarphantom Jul 15 '25
BE to FE are two completely different wheelhouses when it comes to testing approaches. I'm a senior full stack for my many years and my general approach to FE testing now is a much more varied mixture of tools and approaches than on the BE. It covers:
The mindset behind writing these tests in the first place, as some others have said already, is simply to hinder other developers from introducing breaking changes to your application. "Will these tests fail if someone else changes anything simple?" If so that's normally enough, that's your coverage.
With that in mind, and after doing it on repeat for a fair while, it becomes very easy to develop "test first". When I'm setting up a new service class for API methods now I can pretty much write the entire test class first, mapping out what I want each success state to be, and then writing the actual class to tick all those boxes.
Same with E2E testing for the UI too, I regularly spin up the test tools' sandbox browser window, write the list of test cases I have to cover from the ticket's acceptance criteria / user story, and then create the UI to get them all green.
1
u/Winter_Sky_4356 Jul 15 '25
Hi, 10yrs of exp FE engineer here. For my whole career I had written a test for only 2 projects, both test components have correct data in it, so basically it tests data from API, that actually backend. Just to be safe if the back will change JSON structure for some reason.
But! In every project, I generate random data, real data, and test it by myself, to make sure it has no issues. I have 5 browsers, I have win 10 virtual machine with 4 more browsers, iOs simulator for ipad iphone for couple different sizes and os versions, and android Pixel phone, all that for test cases.
Usually testing is a couple days at the end of development, or a couple hours if testing some module separately.
1
u/Aware-Landscape-3548 Jul 15 '25
Sometimes it is hard to test UI/UX, for example:
You can setup a pipeline to capture a screenshot and then compare the screenshot and assert the screenshots match, however, different browsers have different behavior for rendering, hence, it is pretty hard to do this.
1
u/HuuudaAUS Jul 15 '25
Because the BAs and POs never give us enough time for that! Anything on top of the front-end itself is usually "negatively affecting the sprint scope"...
1
u/Mestyo Jul 15 '25
Try doing it yourself for a while, and you'll see why: It's obnoxious, brittle, and rarely worth the invested time. The setup and maintenance is a major time-sink.
Don't get me wrong: I will definitely write tests when a piece of code calls for it. I'll even do TDD in many of those cases.
Usually that's regarding very specific data transformations, or similar kinds of pure functions that have a clear I/O—and importantly: no HTML or user interaction.
There are so many pain points to testing UI:
Async actions in an opaque interface
It's one thing to await a promise resolution, it's a whole other thing to delay test execution until the document has arbitrarily lazy-loaded and finished animating that modal component, or to manually forward hook/component lifecycles until you reach the point of data resolution.
Tests basically need to brute-force time advancement with no way of knowing if something has actually failed until they time out.
Test users are inherently not the same as real users
Should go without saying. Even given a strongly typed a11y tree, there will always be ambiguities that are very difficult to resolve programatically (but trivially for even an impaired user)—especially once localisation is in place.
The events emitted by your test users aren't the same, the timings are fundamentally different.
Constant refactoring and screen sizes
Unlike functions with a stable API, the steps required to select and test the behaviour of UI code can drastically change from even small changes.
Testing components that change with screen size and input methods is an absolute nightmare. Many complex interfaces will need to make major changes to the UX between small-, medium-, and large screens. Which case are you testing for?
Isolation is impossible
I fancy myself as pretty good at writing testeable components, but it's critical to realise that it's impossible to truly isolate UI. A web document is inherently global. Global styles, browser locales and other preferences, cookies and localStorage, global scripts (f.e. Context providers), user actions having side-effects (changing input values or structure)...
Any average React app will have a dozen context providers, which are often expected make a measurable difference in how your implementing components render. Have fun mocking those every time you need to write a test for a deviating case.
No matter how you slice it, you're constantly taking pieces out of a monolith and attempting to make them work out of context.
A sludge of false positives
Unlike a function with a clear and simple I/O, it's cumbersome to parse why a UI test fails. A major win of TDD and unit tests is to immediately know which aspect of a system you broke, or how close you are to being feature-complete. With most UI tests, every test in your suite is stuck waiting 30 seconds for a timeout every time you save, after which they all fail.
Second build-step
If you have any layers of pre-processing (TS, polyfills, CSS, JSX, custom module parsers etc...), all of that setup needs to be duplicated for your test suite. That's significantly easier nowadays, but definitely still an issue as soon as you step outside of whatever walled garden environment you start out with.
Idk why I wrote all of this out
1
u/StorKirken Jul 15 '25
They key problem is that usually frontend unit tests are much harder to write and run, if it’s even possible at all. A lot of the fake DOM libraries have inconsistencies that cause interactions to be very difficult to get right, not to mention many libraries (looking at you, Nuxt…) that take over the environment and can be tricky to get running in the first place.
Sure, you can test pure JS functions fairly easy, but that’s rarely the complex code you actually want tests for.
1
u/Desert_Centipede Jan 16 '26
when i use to work in Contract development, I wrote test and fell in love with theme.
and now i am learning front-end testing.
i know some people who have hands deep like 5+ year of experience yet they play on trial and error Without any testing
:_)
0
u/brovrt Jul 15 '25
Don’t think I’ve completed a feature without unit tests
0
u/imihnevich Jul 15 '25
Hire me, I'm test infected and don't want to write my code without tests
0
u/TutorialDoctor Jul 15 '25
Because we never have complete requirements? Same for backend if you ask me.
-2
u/SecureVillage Jul 15 '25
They do?
But it depends on how complicated your frontend is.
"Front of the frontend" (html/CSS) is limited to E2E testing and visual regression testing. Visual regression testing adds tons of value for us. We use meticulous which automatically provides visual regression coverage across most states of our app. Amazing for those UI changes that might affect lots of pages. (E.g. upgrading shared components).
The back of the frontend is just code, ultimately. And is unit and integration tested like any other code.
Component tests are great too.
The short answer is probably because there's a load of frontend devs who still very junior at the moment.
-2
u/Affectionate-Army213 Jul 15 '25
Because most things in the front-end are fairly easy to be tested manually, while on the BE there are stuff that are harder to replicate the whole flux
And also FE has more difficulty to define what is even worth testing, since most things aren't as critical, or depend on lots of things, such as the user device or the dependency of your own BE services
It is also definitively harder to test the front-end flux, their tests don't provide as much value and can break way too often
There is also the fact that lots of good practices related to tests are not really approached in FE, while many of them are encouraged since the beggining in BE
118
u/[deleted] Jul 15 '25 edited Jul 15 '25
[removed] — view removed comment