48
top 8 comments
sorted by: hot top controversial new old
[-] lonlazarus@lemmy.sdf.org 3 points 1 year ago

Not writing unit tests just isn't an option for a reliable app in the long term. But, it'll take way more than 10 minutes, always.

[-] lungdart@lemmy.ca 1 points 1 year ago

Good tests remove development time, not add to it.

I can't tell you the countless hours saved from automated testing. Red Green refactor for life!

[-] asyncrosaurus@programming.dev 2 points 1 year ago* (last edited 1 year ago)

Not testing is crazy. Once you realize you can actually refactor without ever having the fear you've broken something, there's actually opportunity to make rapid improvments in structure and performance. Taking 2 minutes to write the test can save your hours of debugging. Unless you're building a throwaway prototype, not unit testing is always the wrong choice.

[-] festus@lemmy.ca 1 points 1 year ago* (last edited 1 year ago)

One rule of thumb I've heard and follow is that every time you encounter a bug, you write a unit test that would catch it. I find that does a pretty good job of getting high code coverage, though maybe that's cause my code is naturally buggy ๐Ÿ˜….

[-] bleistift2@feddit.de 1 points 1 year ago
  • Writes test to trigger the bug
  • Test is green without fixing the bug.
  • Dafuq?
[-] aport@programming.dev 1 points 1 year ago

That's why you write the tests first

[-] lemmyvore@feddit.nl 1 points 1 year ago* (last edited 1 year ago)

Here's my take. In order to be able to write meaningful unit tests the code should be structured in a certain way, with very modular, decoupled units, dependency injection, favoring composition and polymorphism over inheritance and so on.

If you manage to write your code this way it will be an objective advantage that will benefit the project even if you don't write a single unit test. But it does make unit tests much easier to write, so presumably you'll end up with more tests than otherwise.

IMO teams should prioritize this way of writing code over high test coverage of non-modular code. Unit tests for deeply-coupled code are a nightmare to write and maintain and are usually mostly meaningless too.

I like to tell myself "the scope of the feature is simple enough that it's unnecessary"

this post was submitted on 28 Jun 2023
48 points (98.0% liked)

Programmer Humor

19169 readers
1486 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS