💾 Archived View for freeshell.de › gemlog › 2021-07-10.gmi captured on 2023-07-22 at 16:34:34. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-11-30)
-=-=-=-=-=-=-
I've been reading people's opinions of unit testing.
(This is an aside, every single company I've worked for the last 12 years has officially said they were doing "Test Driven Development". To this date, I've *never* seen anyone do this. I'm not even sure it exists outside of textbooks and classroom settings. I've seen more compelling evidence of the Loch Ness-monster than TDD. Please let me know if you have any shaky and blurry camcorder footage of this development practice, I'd love to see it ;-)
[raised hand emoji] I do it sometimes, and I got a job by doing it.
When my Gemini client didn't handle relative URLs correctly, I did some TDD. I knew there was one thing to fix, and I wrote tests for the cases that didn't work. But for some other issue where I'd have to change "this, that and the other thing" - well, then I'd probably try changing this, seeing what effect it has on that, and beating the other thing until it all works. I can't see in advance what the test should be.
When I was looking for work, one company sent me a coding exercise to do in my own time. It was specified that there should be "this thing that does this", and "that thing that does that". So I wrote some tests first, then wrote stuff that made them pass. I got the job. They liked the fact that my code worked not only for the example input in the spec, but for unexpected stuff. Later I saw other people's attempts. No tests at all, and even the example inputs didn't work.
I was amused by the original article that Sean quoted.
Nothing should ever be mocked. Period. If you don't agree you likely don't understand many things.
I enjoyed the poster's level of confidence in his opinion. As respectfully¹ as possible, I say nonsense. If we want to test A but it uses B and we don't want to set up the big heap of stuff that makes B work, mocking B is what we have to do. I once mocked an entire mainframe. There was a PC system that called the mainframe to do some lookup. There wasn't a spare mainframe available. I mocked the calling code so it popped up a UI dialog to ask the user what the reponse should be. Problem solved, and the other code could be tested.
¹ That's not a sarcastic "respectfully". The poster has a point about isolating the thing that might need mocking. When you think you need a mock, you always have the option to redesign all the code. Of course you'd have much more confidence in that if you have some decent test coverage...