this post was submitted on 01 Sep 2023
337 points (96.2% liked)

Programming

17524 readers
334 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] SpaceCowboy@lemmy.ca 3 points 1 year ago (1 children)

Yeah creating tests for every single method is insane. If a feature changes it's more difficult you either have to figure out how to implement the change without changing the method, or you change the method and have update the unit test. But if you're constantly updating the unit tests, how do you know if you might've broken something else that the test was intended for.

It's way better just to do integration tests that match the feature request. That way the feature that someone asked for will continue to work even if you decide to refactor the code.

[–] Alexstarfire@lemmy.world 3 points 1 year ago (1 children)

Unit tests are only worthwhile if you refractor code or write the unit tests before writing the code. We started adding unit test for most everything where I work and I think it's far more effort than it's worth. It's not that it catches nothing but it catches so little I don't think it's worth the time spent writing them.

[–] Double_A@discuss.tchncs.de 1 points 1 year ago (1 children)

Code changes that could affect tests happen all the time. It doesn't need to be a specific refactoring of that unit.

[–] Alexstarfire@lemmy.world 1 points 1 year ago (1 children)

I don't think you understood my point. That's exactly why I think unit tests aren't all that useful. Most code changes require updating the unit tests so unless you change the unit tests first all that's being done is saying, yep this works how I programmed it to work.

[–] Double_A@discuss.tchncs.de 1 points 1 year ago* (last edited 1 year ago) (1 children)

But if unit tests that other people wrote unexpectedly break, you know that you changed things that you maybe didn't mean to change.

[–] Alexstarfire@lemmy.world 2 points 1 year ago

Ideally. It's just that more often than not it means you need to update the unit tests. I can still use my fingers to count how many times a unit test has caught a mistake I made, and I've been at my job for 10 years.

I'm curious if others have a different experience.