DEV Community

Discussion on: Whatever happened to the test pyramid?

Collapse
 
cescquintero profile image
Francisco Quintero πŸ‡¨πŸ‡΄

I think Unit tests are not suited for modern frontend development. I'm a backend developer and doing Unit testing in RoR is simple and makes all the sense as we have classes and instance methods.

In modern frontend frameworks, it looks more obvious to do integration and snapshot testing and this has been a good experience my coworker has had in one of our projects.

I also think is important more frontend developers start/continue doing testing BUT the testing the helps them do their job and doesn't add trouble to their daily tasks.

Collapse
 
d_ir profile image
Daniel Irvine πŸ³οΈβ€πŸŒˆ

You may be aware of this talk between DHH, Martin Fowler and Kent Beck, which came about as a result of confusion about how to unit test Ruby on Rails.

Frameworks do make it harder to unit test, but it doesn’t make it impossible.

With Ruby on Rails a key example is Active Record. This pattern makes it difficult to write ”unit” tests because it’s hard to test an Active Record model without interacting with a real database resource. For some people this breaks a rule about what a unit test should be. They then replace Active Record with something like the repository pattern. For people like myself, we just shrug our shoulders and use the database, and still call it unit testing. Sure, my tests aren’t as fast as they might otherwise be, but I’m still gaining all the other benefits of unit tests over higher-level tests.

On the front-end... I think your use of the word simple is important. People don’t believe that unit testing UI code is simple. In my opinion, that’s why they don’t do it. And since I know that I’m having a lot of success with unit testing on the front-end, I’m trying to share that knowledge with others.

Collapse
 
cescquintero profile image
Francisco Quintero πŸ‡¨πŸ‡΄

I'm in the group of people who think doing unit testing in frontend isn't simple πŸ˜†

One of the reasons I think people feel that way is that it isn't obvious what to unit test in frontend world. Do we test styles? Do we test structure of HTML? Of course we should be testing JS functions but what about event handlers? Probably we've been doing it wrong.

And even though your article answers those questions, doing unit tests in the way you mentioned isn't as easy as frontend devs would like/hope.

since I know that I’m having a lot of success with unit testing on the front-end, I’m trying to share that knowledge with others

Then I hope to see your content about this topic πŸ˜ƒ

BTW, I wasn't aware of the DHH, Fowler, and Beck video. Thanks for sharing πŸ‘πŸ½