DEV Community

Cover image for Why unit test culture is broken

Why unit test culture is broken

Francis Luz on August 03, 2020

Write unit tests should be as fun as writing your feature code, no matter which language you're using, it's all code at the end of the day. ...
Collapse
 
pentacular profile image
pentacular • Edited

You need to consider the problems you're trying to solve with unit tests.

These may be:

  1. Documentation in the form of examples.
  2. Defense against regression.
  3. Evidence that the code functions correctly.
  4. Something else.

Once you understand what problem you're trying to solve, you can try to figure out how well unit testing achieves these for you, or if there a better alternatives.

But if you don't know why you're doing unit testing, except that TDD is good, then you won't be able to make a reasoned assessment, since your position will be ideological.

So, I suggest focusing on the actual problems rather than on a particular approach.

Collapse
 
francisluz profile image
Francis Luz

Thanks for enriching the discussion, completely valid points. I wrote this more because of past experiences and talks with friends. Unfortunately, some projects nowadays still don't have a good unit test base. I'm lucky enough to have it working quite well in my projects.

Collapse
 
waylonwalker profile image
Waylon Walker

Writing tests early helps a ton. It doesn't have to follow TDD to a T, but often we are writing code, then checking the output of a bunch of things. Unit Testing is an amazing tool to help speed up this process and give us confidence in future releases.

Stop manually checking things and just write a test already!

Collapse
 
xowap profile image
Rémy 🤖

I guess it's broken because there was a rushed sprint and someone forgot to update test cases

Collapse
 
tateronaut profile image
tate shepherd

In my experience this is one of the biggest causes for tests not getting written. Rushed feature pushes. So what gets left out? Tests

Collapse
 
waylonwalker profile image
Waylon Walker

Or it's not engrained into team culture.

Collapse
 
francisluz profile image
Francis Luz

Couldn't agree more ;)

Collapse
 
vdedodev profile image
Vincent Dedo

I find writing tests to be quite enjoyable, mostly unit tests because of the fast feedback and the lack of dependencies I have to mess with. I use unit tests mostly for checking things work, being sure on edge cases and documentation. The thing that ruins the fun of writing tests is TDD, so I write tests after the code and that works well for me.

Having too much reliance on unit tests is the pitfall here, they're usually brittle and make refactoring more expensive, which will often be mocks being wrong after the change.

Collapse
 
moopet profile image
Ben Sinclair

So... why is unit test culture broken?

Collapse
 
francisluz profile image
Francis Luz

Thanks Ben, well in my point of view, there're a number of things... to point out a few I would say:

  • Unit test is not part of you development process
  • Rushed sprints with poor test cases
  • "Clients don't pay for it" I guess this is more company/team culture

Those are some that I can tell, make sense?

Collapse
 
moopet profile image
Ben Sinclair

I guess you're mostly saying that it's a problem because people don't do them? I thought from the title you meant that people were doing unit tests but something was wrong with the way they were done.

Thread Thread
 
francisluz profile image
Francis Luz • Edited

Wow, got it... yes I meant to say more about the culture of doing it itself.

Collapse
 
campkathleen3 profile image
Kathleen Campbell

Its not totally broken, Its followed by many testers. There are some rules and techniques to follow. May be this will be helpful. dev.to/campkathleen3/explain-unit-...

Collapse
 
vptvix profile image
Vinicius Torres

Great man.

It’s about culture