Ask HN: How much time do you invest in writing tests?
Any tips/tools to get to similar coverage in shorter amount of time?
Any tips/tools to get to similar coverage in shorter amount of time?
Note the key difference here: invest vs. spend. Time spent on writing good automated tests is an investment. That investment pays dividends every time the test suite is ran. On the other hand, time spent manually testing is lost. If you ever want to run the same test, you have to spend the same amount of time.
I gave a presentation on continuous integration and testing at PyOhio that goes into this idea in more depth: https://m.youtube.com/watch?v=K-iii4kMLWE
To answer your question: as much as it takes. We work hard to never ship code that isn't well tested. I don't even think in terms of writing code without tests anymore, the testing is just a part of the overall process needed to finish the job.
Well I totally understand the benefits of automated testing. That's not the point here. My motivation for asking this question was to see how much time does it take for others to write automated tests (measured as % of time spent in coding the feature itself). If it's significant chunk of time, can we build some tooling to speed up this process?
Here's a blog post if you're interested in using it: https://gocardless.com/blog/getting-started-with-coach/
I’d estimate 25-50% at least depending on the complexity of the feature.
The point above is valid though, how much time was spent dealing with the fall out of not writing tests? Not easy to measure unless people are meticulous about tracking hours over numerous releases which probably doesn’t happen. Leads and managers need to see the ROI in a visible and measurable way.
How do you get similar coverage in shorter time? Keep doing it. In a few years it will be second nature, and you'll stop seeing it as a separate activity, but a natural part of feature development.
Practice will definitely help. Do you think that there is lack of tooling in this space?
If someone said they take longer to think about the code than to write the code, we'd instinctively guide them towards saying that's natural.
Writing tests is very much a way of thinking through a problem and bringing clarity to exactly which piece you want to solve at the time. That is always going to take longer because it involves thinking through the problem first. It's natural.
The answer to how much time is invested into writing tests?
For me, it's usually more than the time taken to write the code to pass the tests. By the time I'm done writing the tests I know what I need to do to make it pass.
A second answer to the question is, as much time as it takes. Because I definitely don't want to repay that time later in the form of regressions and stress when change comes knocking at the door.
however, i do write functional tests for all my api endpoints. this gives me pretty solid coverage and a good balance of not over testing.
"Let's see, I need my setup to be X. Well, this other test has a setup X' that is almost the same; I'll just copy that and tweak it. Then I need to open a connection to server Y; this other test does that. Copy again (or make it a subroutine)..."
After all of that, I only have to write maybe 20% of the test. That makes it a lot faster...
1. I've built up "muscle memory" for common patterns.
2. I've learned where I'm over-testing and that I don't need to write as much.
3. I've altered how I write code in order to make it easier to test. A common sign it will be harder to test is if I get data from an outside source that I didn't provide to the function/class.
60% devtime on larger systems with millions of lines of code that will live on.
We used to test on smalller applications as well, but we rarely had a need for it because the systems rarely changed until technology and architecture forced rewrites. Like moving from windows based applications to asp.net web-apps to apis with JS fronts to cloud native.
Our productivity is up by 80% because we mainly do smaller, single to few function apps and our debugging time or the amount of user experienced problems hasn’t increased.
I can't say percentage because sometimes I spend days on tests, sometimes I write no tests. (https://www.youtube.com/watch?v=Vaq_e7qUA-4&feature=youtu.be... is my attempt to explain how I decide.)
Also consider whether you really need a test: https://robdmoore.id.au/blog/2015/01/26/review-of-jimmy-boga...