DEV Community

Manu Lopez
Manu Lopez

Posted on

How would you convince your company to implement unit tests?

Scenario

Suppose you are working in a super cool company, your coworkers are great and your job is fulfilling, but your company doesn't implement unit testing as it doesn't see any benefit from a business point of view.

What would you do?

As the title asks, how would you convince your company unit tests are beneficial? Would you try to convince from a technical point of view or a business point of view?

It would be great to read your comment!! ☺️☺️☺️

Top comments (29)

Collapse
 
ben profile image
Ben Halpern • Edited

For us, it helped to implement the tools that measure code coverage and give grades, like Code Climate. Somehow it's a bit easier listening to robots.

Code coverage is a flawed measurement, but it can help in a lot of ways

Collapse
 
manu profile image
Manu Lopez

Thanks for your comment Ben, I didn't know Code Climate! It looks quite interesting.

Collapse
 
ripaz profile image
Ripaz

Yeah, pretty nice tool I didn't know it existed. I will try to push it up in the next meeting with a team.

Collapse
 
coolgoose profile image
Alexandru Bucur

I would say try first to push for functional tests before if it's a web shop.
It always depends on the types of the projects and the allocated budgets.

Try being practical, like, hey guys, remember the time when the 'register' part of the website didn't work because of push X? Here's a way we can easily test for that. Having clear examples is always a good first step.

Collapse
 
quii profile image
Chris James • Edited

Who is "them" ?

If it's your developer colleagues you shouldn't have too much trouble convincing them of the benefits, writing tests has more or less been industry standard for around 10 years now.

In short

  • Less bugs
  • Much safer refactoring so easier to change code
  • So faster development in the long run

If it's management, I would contest that you do not work at a super cool company. Do you ask permission to write classes? if statements? In 2018 writing tests is just as much as being a developer as refactoring is.

As a professional you are the expert being paid to make the right decisions as to how to make a maintainable system, not management.

Collapse
 
manu profile image
Manu Lopez

Thanks Chris for your comment! Maybe I was wrong saying that was a super cool company in the example but that was to focus in the unit test topic (pros and possible cons) and not in another business issue like supervisors don't listen to you or something like that. I really liked you thought in both tech and management terms.

Collapse
 
rhymes profile image
rhymes • Edited

Do they have functional / integration tests or no tests at all? Unit tests might not be worth it in some scenarios, especially if you have to deal with a legacy app with no tests.

I would bring up the rate of bugs and regressions and start from there. In the meantime you can start testing your code and maybe start adding those few tests in the CI pipeline.

Collapse
 
manu profile image
Manu Lopez

Thanks for the comment! I think the rate of bugs is a very good point.

Collapse
 
alainvanhout profile image
Alain Van Hout • Edited

It’s a basic truth that (a) adding features and (b) being relatively bug free, are equally essential to most businesses that want to attract and retain customers. Unit tests allow you to focus on the former, while having confidence that you’re doing fine with regard to the latter.

Collapse
 
theinfamousrj profile image
RJ Hill

Convincing the company could be one of two things and I’ll just address them both.

Convincing leadership that you need tests of any kind is simple: “we need to do a little bit more work now in order to ensure that when someone new comes along and breaks things, they know immediately, without asking another developer, that something is wrong.”

Convincing other developers is also fairly simple: “we write unit tests so that when we break stuff we can get instant feedback on what we broke. We might even have planned for that to break because we’re changing a contract, then we see it break and have confirmation of that.”

Collapse
 
k4ml profile image
Kamal Mustafa

Unit tests might be hard to sell. Even at my current company, we have very little unit tests. But we have lot of tests, mostly functional and integration tests that being automated. Tests that every developer can run with just a single command make tests, or hook up into CI tools that automatically run on open PR or certain commits. This is much easier to sell. Who don't want just sitting around while computer do the work, instead of endless clicking and typing the same thing over and over again.

It amazed us when people say we don't do testing. What? You didn't test your code. So you just wrote it and ship it, and it just work? That's heaven. What they actually mean is that they don't automate their tests. Truth is, everyone are doing tests, the moment they write single line of code. This I think the crucial understanding we must put first. When we talk about writing tests, people think that it totally new things, so it must be hard and probably not worth doing it. But once we make them realized that it's no different than what they already doing (just being more efficient), they will start seeing the value of doing it.

Collapse
 
sandordargo profile image
Sandor Dargo

A former agile coach of ours told a story from back in time he was a CTO. Top management didn't want to invest in (unit)testing, they didn't support the idea to say the least.

One evening the CTO told the big boss that he could save him X amount of money very simply. Words went on, this future coach showed the CEO how to implement unit tests and how they help to prevent bugs.

The next days, communication arrived from the top that everyone should write unit tests for the new code.

So try to sell it with what the business like. They like more revenue and less money spent.

Collapse
 
manu profile image
Manu Lopez

Thanks for the comment Sandor! I think your comment could be really helpful for many developers as it shows that companies sometimes only listen to business reasons and not too technical reasons. Sometimes we lack in the way we communicate with non-technical people and this could be a good example.

Collapse
 
theringleman profile image
Sam Ringleman

Is funny because I'm right in the middle of this exact dilemma. I was handed a large project and part of that is a major refactor of one of our mission critical components. So I am building my integration to work independently and then when it comes to making the full switch I'm going to fully build out all tests. I have a feeling when the transition goes smoothly, without breaking anything, my lead will see the value.

Collapse
 
manu profile image
Manu Lopez

Thanks for the comment Sam and I really hope everything is going well with these tests. An interesting approach could be to try to "sell" unit testing from a business point of view (pretty simple example: spend less time fixing bugs and you will reduce costs in that project). Keep us up to date with the project refactor and testing!

Collapse
 
delbetu profile image
M Bellucci

I wonder why people don't implement unit tests?

Our industry made awesome progress when deciding to start writing tests as the standard, but still need to add the DESIGN!
Which for me implies thinking/writing the software as interconnected pieces which play different roles.
At that point, writing isolated tests for those Units should be the norm.

Collapse
 
delbetu profile image
M Bellucci • Edited

Sorry I didn't answer your question.
I would start writing my own unit test.
People will start making comments against them in your PRs
And there you can point them to the literature, or talks around this topic.

A good tip for writing easily isolated tests is:
1- Search in the code for classes which have no dependencies and write a spec for it.
2- If you see a repeated behavior in two different classes Apply the Extract class refactor and create an isolated test for this new class.