Management keeps asking when we will write unit tests, and I tell them I’m too busy fixing bugs, because each time I fix a bug I 1) examine the entire code base to find any similar problems 2) implement full parameter validation in that code to try to ensure it can’t happen again and 3) add exception logging code so that we will get an immediate error reported directly on the line it occurred if it does. If I have an…
Why Most Unit Testing Is Waste [pdf]
151–159 of 159 posts
Re: Why Most Unit Testing Is Waste [pdf]
#152Management keeps asking when we will write unit tests, and I tell them I’m too busy fixing bugs, because each time I fix a bug I 1) examine the entire code base to find any similar problems 2) implement full parameter validation in that code to try to ensure it can’t happen again and 3) add exception logging code so that we will get an immediate error reported directly on the line it occurred if it does. If I have an…
I'm curious what you consider examining the entire code base to find similar problems. If this is more than a 5-10 minute search then I would feel like it's a significant waste of time. And if it is more than that amount of time and you are continuing to find bugs then I would ask what is the problem that allows the same bug to surface in multiple places where it is easy to identify but hard to search for?
The cause was that one of the VIPER classes forced unwrapped an optional reference to its view. Force unwrapping is without the if, just assume it’s always valid and crash if it’s not.
The problem was they made this assumption because the view is never nil except for one uncommon edge case, if a network operation completed after the view was disposed. So the fix was easy, remove the force unwrap (you should never force unwrap in Swift, it’s terribly bad).
But what about our other VIPER views? It took me a couple minutes to review all 20, and Trey all had the same identical flaw. Fixing them took seconds, but individually testing the fixes took a few hours.
Should I have left those other 20 views alone so our app could mysteriously crash for some of our hundreds of thousands of users?
A more recent bug I found on my own was a memory leak caused by our main views network closures holding strong references to the ViewController. This caused code to fail that was still in old dead copies. So I fixed the closures and we no longer have old copies of the VC handing around forever. I didn’t have time to do a search at that moment, but I took notes in my dev log so I can review every view controller (50 or 60) for similar problems. Why wouldn’t I? How many known bugs and random unduplicated problems would go away if we got our Viewcontrollers memory Managemnt right? im betting at least a few, and that I’ll eliminate some future problems before they can even be found.
Software engineering is usually 80% fixing bugs. Developing rigorous standards to prevent their formation can give you much more time to build new and improved features.
Re: Why Most Unit Testing Is Waste [pdf]
#153Re: Why Most Unit Testing Is Waste [pdf]
#154Earlier quoted context omitted.
Yes, but devs who don't write unit tests are probably not going to write integration or acceptance tests either. Maybe except of a one guy who I talked to a while ago. He does not write unit tests, because static type checking in C++ takes care of everything that unit tests do (according to him), but I actually have seen his code that contained few system tests, so there are exceptions.
> devs who don't write unit tests are probably not going to write integration or acceptance tests either Why do you think they aren’t? I don’t write unit tests except when I’m specifically paid extra for that (yes, coding strongly-typed languages too), but I do write other kinds of tests as I see fit.
Btw, what type of software do you write and how do you know if it actually works?
Re: Why Most Unit Testing Is Waste [pdf]
#155Earlier quoted context omitted.
Yes, but devs who don't write unit tests are probably not going to write integration or acceptance tests either. Maybe except of a one guy who I talked to a while ago. He does not write unit tests, because static type checking in C++ takes care of everything that unit tests do (according to him), but I actually have seen his code that contained few system tests, so there are exceptions.
Except that the featured article isn't saying not to worry about testing at all, it's about how to actually get value out of your testing.
I guess the main reason for my condescending sentiment is due that the author gives 0 examples of code that requires tests vs code that does not so it is actually not.
Re: Why Most Unit Testing Is Waste [pdf]
#156Earlier quoted context omitted.
> devs who don't write unit tests are probably not going to write integration or acceptance tests either Why do you think they aren’t? I don’t write unit tests except when I’m specifically paid extra for that (yes, coding strongly-typed languages too), but I do write other kinds of tests as I see fit.
Doing TDD is a habit and if a developer does not find unit tests useful or practical, then I don't think they are going to write tests that are more complicated than unit tests. Btw, what type of software do you write and how do you know if it actually works?
I find unit tests are useless for most cases. But this doesn’t stop me from writing more complicated tests. Even unit tests when they’re useful. E.g. for sufficiently complex low-level SIMD math routines: inputs & outputs are simple, no IO, no multithreading, no large dependencies, no side effects, just some computations, and tons of weird _mm256_verb_typesuffix intrinsics everywhere i.e. it’s very easy to make mistakes writing these.
> what type of software do you write
Lately Windows CAD and Linux embedded. Previously mobile software, PC and console videogames, CNC & robotics, GIS, WinCE/embedded, multimedia/video codecs, utilities for Windows administration, lots of other stuff.
> how do you know if it actually works?
I use strongly typed languages that catch 99% of stupid errors at compile time. I test it manually while using debugger at the same time to inspect internal state. I design my software to be testable, e.g. logging, asserts, configurable debug dumps, well-defined interfaces between components so they can be tested in isolation, etc.
P.S. Today I’ve fixed 3 bugs in my code.
[Windows] A user tried using my software on old AMD CPU, it didn’t work ‘coz SSE 4.1 instruction set is not supported.
[Windows] Under some conditions, my code reads value from a depth+stencil D3D texture while the GPU is still rendering previously submitted commands into the same texture, read fails.
[Linux] When both HDMI and DSI displays are connected, my DRM/KMS client code selects the wrong one.
All three are caused by environment or external hardware, and you can’t unit test these.
Re: Why Most Unit Testing Is Waste [pdf]
#157Earlier quoted context omitted.
But exactly these tests tend to be the useless ones that just pass and don't find bugs. On 2 separate occasions I had an app with extensive unit tests that seemed to work fine but also seemed to have strange rare bugs. Both times I wrote a single additional "unit" test that fired up the environment (with mocks, same as the other unit tests) but then acted like a consumer of the API and spammed the environment with ra…
A test can still be simple while providing garbage edge-case data. In fact that’s usually one of my default tests to ensure that I have a well-defined behavior even in these cases.
Re: Why Most Unit Testing Is Waste [pdf]
#158Earlier quoted context omitted.
But exactly these tests tend to be the useless ones that just pass and don't find bugs. On 2 separate occasions I had an app with extensive unit tests that seemed to work fine but also seemed to have strange rare bugs. Both times I wrote a single additional "unit" test that fired up the environment (with mocks, same as the other unit tests) but then acted like a consumer of the API and spammed the environment with ra…
Your API-spammer interface reminds me of the Macintosh "Monkey": https://www.folklore.org/StoryView.py?project=Macintosh&stor...
Re: Why Most Unit Testing Is Waste [pdf]
#159Earlier quoted context omitted.
Did that many times without problems. But, I mostly code C++ and C#, both are strongly typed, so the compiler helps a lot with refactors.
Exactly. Most proponents of unit tests use horrible programming languages; they are afraid to change code because anything could break at any time. Stop using those languages and most of the problems 'fixed' by unit testing just disappear.