22

A discussion about writing tests for frontend applications.

Context: my frontend coworkers don't write tests, at all. Yeah, really. Our testing process is very manual. We test manually when developing. We test manually when reviewing code. After merging, the application is deployed to a staging server and the design team does a QA Sprint. Lots of manual testing and some bugs still crawl by.

So I decided to start pushing my coworkers to start writing tests. One of the reasons I constantly hear them say to not write tests in the frontend is: "It's not worth the time, because design keeps changing, which means we have to take time to fix the tests. Time that we usually don't have."

I've been thinking about this a lot and it seems to me that this is more related to bad tests than to tests in general.

Tests should not break with design changes (small changes at least). They should test funcionality, not how things look. A form should not break if the submit button's style changes, so why should its tests fail? I also think that tests help save time, as they prevent some back and forth because of bugs.

Writing good tests is the hard part. Tests that cover what's really important and aren't frail and break with things that shouldn't break them. What (and how) should we test? And what shouldn't be tested?

Writing them fast is another hard thing. Are you doing it right if they take more time to write than the actual code?

What do you think about this? Do you write tests for your frontend applications? What do you test? How much time do you spend writing tests? What are your testing tools/frameworks?

Comments
  • 5
    For those of you that use react and want to learn how to write tests, this course is free until Thursday: https://frontendmasters.com/courses...

    I watched it on the weekend and took some things I'll try to implement at work.
  • 2
    I feel pretty guilty. I don't even write tests for my backend .. forget my frontend.

    yes, I deserve good spanking :(
  • 2
    @CurseMeSlowly our backend team writes tests for everything. They have an amazing code coverage. Not 100%, but still amazing.
  • 1
    Just wanted to point out Jest and then saw that your link to the free course is all about Jest.

    We also use it for frontend testing, but only for where we think it really matters (i.e. the Reducer structure).

    Would love to use and understand it more, so your link is very welcome, thanks.
  • 1
    @finiteAutomaton yeah, on the rare occasions that we do write tests it's usually to tests redux stuff, too.

    I've been experimenting react-testing-library and it's been nice so far. Actually rendering the elements like in the browser is much easier to comprehend than enzyme's shallow rendering bullshit. Every time I tried using enzyme I lost hours trying to understand what was going on.
  • 0
    But I don't want to make this about react. I also want to hear the opinions devs that use vue, angular, vanilla, etc.
Add Comment