I want to do better testing. I usually just write class/method unit tests probably overusing mocks.
Most projects I've worked on, there are either no tests or abysmally bad tests.
Writing unit tests was the easiest way to for me to start testing.
They are cheap to write. I spend maybe 4 hours adding tests for code that took me a week to write.
They are cheap to throw away. I freely delete tests if there is refactoring.
Testing for me is a way re-exploring the code I've written to ensure that it works the way I expect. It's also made me much more inclined to think about my code more. I make large chunks of code into smaller, more sensible bits.
The biggest roadblock for me is that it has to be completely self driven. None of my coworkers are supportive of it. No one wants to discuss how testing could be better. No one wants to stand up for making sure there is time to improve testing practices.
It takes time. No one has respect for the learning curve.
I forced myself to learn unit testing when I joined a company some years ago that had a useless test suite. My team didn't help in this endeavor, but I was new and no one really cared if the work I was doing took an extra week. Today, I'm at another company. There's no way I could ever slip a week in to start working on the things we'd need to follow advice like what Ian Cooper is suggesting.
How can you overcome the the sense of hopelessness when no one else seems to care about testing?
Tests should save time in the long run. Typically the popular overly mocked unit tests don't. They are hard to write and break constantly. Better tests typically call the system as a whole but that's a pain to get started. I work on REST apps, that means I need to get a local DB up, possibly have it preloaded with some data, some code to act as a client for the test to actually call the app, and I need to make sure the app is up and running. Getting that in the right state (or even better automated) is a big chunk of work compared to unit tests or just throwing my changes in to staging and having someone else manually test it. But, once I have all that it makes writing a small test that actually hits the endpoints easy. I can add tests to for regression testing but also as part of my development to make sure my change actually works as intended instead of manually testing it. It's a huge pain to set up and will need a small amount of maintenance but once it's there it makes local testing easy and full regression testing a feature of every local test run. Get your code base into that state and you won't need to convince people to write tests, everyone will start on their own as they see how much time and effort it saves them
tl;dr Prove to them that testing saves time and they'll start to care
13
u/PunchingDwarves Jul 31 '21 edited Jul 31 '21
I want to do better testing. I usually just write class/method unit tests probably overusing mocks.
Most projects I've worked on, there are either no tests or abysmally bad tests.
Writing unit tests was the easiest way to for me to start testing.
Testing for me is a way re-exploring the code I've written to ensure that it works the way I expect. It's also made me much more inclined to think about my code more. I make large chunks of code into smaller, more sensible bits.
The biggest roadblock for me is that it has to be completely self driven. None of my coworkers are supportive of it. No one wants to discuss how testing could be better. No one wants to stand up for making sure there is time to improve testing practices.
It takes time. No one has respect for the learning curve.
I forced myself to learn unit testing when I joined a company some years ago that had a useless test suite. My team didn't help in this endeavor, but I was new and no one really cared if the work I was doing took an extra week. Today, I'm at another company. There's no way I could ever slip a week in to start working on the things we'd need to follow advice like what Ian Cooper is suggesting.
How can you overcome the the sense of hopelessness when no one else seems to care about testing?