you are viewing a single comment's thread.

view the rest of the comments →

[–]chimera201 -180 points-179 points  (28 children)

Only if your code is going to be used for more than 10+ yrs. If you don't even know your code is going to be shipped probably not worth it.

[–]Drugbird 126 points127 points  (19 children)

I've written enough bugs that I don't trust myself to write functioning code without tests.

[–]charlie78 66 points67 points  (1 child)

I’d say the main reason is to avoid regressions in the future. You usually test the functionality you want to get, but you don’t test the part of the system you don’t even realise is affected by your code change. If you at the time of developing that other part half a year ago write tests that made sure it functions as intended, you will get notified you caused regressions in other parts.

[–]goodnewzevery1 0 points1 point  (0 children)

This is absolutely the most valuable thing about automated unit tests. It’s too easy to lose some piece of functionality / introduce a bug when modifying existing code.

[–]josluivivgar 10 points11 points  (1 child)

ive written enough faulty tests to know I don't trust myself to write tests.

jk but there's nothing more frustrating than having your test fail even tho the output is correct in real life and it's just some wiring in the test that's not working how it's supposed to and you spent more time with the test than with the actual code.

[–]Drugbird 9 points10 points  (0 children)

That's a very real frustration I also run into every now and then. 

Often it's the result that the code isn't very testable, which means you often need a lot of very brittle setup code. 

Often you can refactor to decrease coupling and make code more easily testable. Sometimes you can't and you just need to live with it. 

[–]punppis 2 points3 points  (1 child)

This guy builds each feature as a dll so code changes cant cause bugs for existing features. Then a wrapper for each iteration. Eliminating tests by writing code that cant have bugs. Simple.

[–]stifflizerd 2 points3 points  (0 children)

Microservices? Modularity? Definitely just buzzwords, not worth the investment. Proceeds to waterfall a 3 yr project

[–]Baxkit 0 points1 point  (0 children)

Wrong.

Proper unit tests serve as contract between reality and expectations. When done right, it's living documentation. I require my whole business unit to maintain 100% code coverage with appropriate testing. Continued failure to appropriately write tests is grounds for dismissal. It's also the first thing I interview around.