DEV Community

Benjamim Chambule
Benjamim Chambule

Posted on

Why write unit tests

What do you tell to someone who keeps asking you "man why do I need to write code to make sure my code is running correctly if I can always debug my code while in the development time?"

Top comments (5)

Collapse
 
jmcp profile image
James McPherson

Unit testing is your insurance policy - that (a) what you've written does what you say it should do, and (b) that when you or somebody has to make a change, It Can Be Confirmed That You Haven't Broken Things.

How can you prove that it works if you haven't got a test for it?

Collapse
 
benchambule profile image
Benjamim Chambule

I totally agree with you. But I know a lot of people who would rather debug during development and/or if something is broken than writing a test. Specially when one is maintaining legacy code which was not built with unit tests in mind.

Collapse
 
jmcp profile image
James McPherson

That's an opportunity to bring things (and people) in from the cold. It's a mindset shift, but one which makes us better programmers/developers/engineers. That in turn means that we've got a "layer 8" problem - and that's where our person-to-person abilities need to be brought to bare.

Collapse
 
deciduously profile image
Ben Lovy

Unit testing is automation. Why use your development time to debug something that can be handled automatically for you, much more quickly than you can do it yourself?

Collapse
 
benchambule profile image
Benjamim Chambule

Yeah! We gain a lot from writing tests, but there are people who can't see any advantage in that! For them it's just a waste of time! They would rather keep adding features than writing tests to make sure their features behave accordingly