Day 19: edge #mbsept

The edge of a train station platform showing part of the rail line and the message Mind the Gap

I was designing something for work a couple of months back. I got a little fancy and added a domain-specific language to the first draft, thinking that it could be useful for handling some special case requirements from the business that we haven’t considered for. I pulled it out in a later revision, thinking to myself “nah, you’re not going to need that anytime soon.”

Well, some changes came through from the business today, and now I wish I kept in that DSL. It hasn’t even been a week. 😛

P.S. I tend to add DLSs into every single project I build so don’t take this post as justification to add a scripting language to your next project just because “it could be useful”. 😉

About Mocks In Unit Tests (Again)

How can one gain confidence that what they’re testing works if one is using mocks?

I’m grappling with this now as I go through making changes in one of the services I’m working on. So much of the logic requires rework, which means the tests will need to change. And yes, the tests use mocks, meaning that the changes are significant.

But do they have to be? We’re effectively mocking things that can easily run as part of the test. Things like a DynamoDB store — which can run within a Docker container — or even services from other packages. Sure they’re not part of the “unit”, so using them in a unit test won’t make it a “unit test” anymore. But I’d argue that using “real” implementation of dependent systems would produce more confidence in the changes I’m making. I’m able to change the logic without changing much of the test itself. Surely this is worth the “unit test” purity price.

And even if the outcome is meant to change, that intention is made clear by simply changing that in the test, without touching any of the setup code. Nice and readable in the MR: the function was expected to do this, now it does that.

That said, I would concede that there’re legitimate cases for mocking. Namely, if it takes a significant amount of time to setup the dependencies, or you can setup the dependencies within the test itself, mocking is probably the best option. A slow test or, even worse, a test that won’t run if dependent services are unavailable, is worse than a bunch of mocks.

Maybe a good compromise is recognising that excessive mocking in a unit tests is a sign that a module has too many dependencies.

Day 18: fabric

My woollen blanket, knitted by my nonna. #mbsept

Red blanket draped on the arm of a burgundy couch

Getting to the point in the photo blogging challenge where I’m saying to myself: “have I posted this photo before?” One of the candidates I had for today, the answer is actually yes. Fortunately I do have an alternative.

Day 17: intense

Didn’t time this photo well. There’s usually an intense game of soccer on this pitch most Saturdays. The Sunday crowds are a little more serene. #mbsept

An empty soccer pitch with a couple of people playing with their dogs

Spent some time today building a site for my Go utility packages. A feature I’ve decided to add is a Go template playground, where you can test out Go templates in the browser. Not something I’ll use everyday but I’ve occasionally wished for something like this before. Could be useful.

The template playground, with a field for the template saying 'hello what', the data which has 'what' equal to 'world' in Json, and the output which is 'Hello, world'

Still waiting for the dream to be able to write code on an iPad. There are some good native apps out there for checking out Git repos and editing files with syntax highlighting, but I never use them because there’s nothing in the OS that integrates them all. You’re left with switching between them to do something in your workflow, which is disorientating as each one will take up the whole screen and throw away your context. I suppose there might be Shortcuts — I haven’t explored what it’s capable of — but what I really want is a shell.

The closest that worked for me is a Code Server web-app running in a chromeless browser. It works for me mainly because there is a shell. If the editor doesn’t support a feature, I can use a command to do what I need. I don’t have to switch between apps either: I can see what I’m doing and the files I’m doing it to. I can also build and run them code I’m writing. Fancy that!

Day 16: oof!

I can’t understand people that stay up until midnight most nights. It’s only 9:00 and I’m already exhausted. #mbsept

A digital oven clock that reads 20:59.

Day 15: red

Red mailboxes means the post will go faster. 😉 #mbsept

A red Australian Post mailbox

Day 14: statue #mbsept

Statue of a winged lion on a brick pedestal

Enjoying coffee and breakfast after a really early start and several weeks of hard work, with the satisfaction that the work is now done. Good feeling. 😌

Day 13: glowing #mbsept

Sun rising on a road with buildings on the sides and tram lines down the center

Day 12: panic

There have been a fair few stressors in my life recently, both at work and personally. And although they haven’t got to the level of panic, they have been a little overwhelming. It’s hard to believe it in the moment, but I guess they will eventually pass in time. #mbsept

Photo of the 'Keep calm and carry on poster'

(Source)

Day 11: retrospect

This photo taken eight years to the day: part of a Roman wall in Exeter, UK. #mbsept

A Roman wall beside a modern footpath within Exeter.

Day 10: cycle

Bicycles at the station. Really need to get on my bike and buy one for myself. #mbsept

Two bicycles at a bike rack.

I’m no fashion expert, but I’m guessing that if you were to stand on the corner holding this sign, you’re going to stop traffic. #dadjoke

A hand-held stop sign resting on a fence.

Day 9: language #mbsept

A sign that reads 'Protected Native Vegetation' in English, Greek, Macedonian, Italian, Mandarin, Vietnamese, and Arabic

Finished reading: What to Do When It’s Your Turn by Seth Godin 📚

Day 8: yonder

I’ll let the arrow do the pointing. #mbsept

A road in a car park with an arrow pointing to a light-house behind some shrubs