Quality Coding

All posts by Jon Reid

Emoji: Label

Unit Test Naming: The 3 Most Important Parts


​You run your unit tests, and get a failure. How many times have you had to dig through the test code to try to understand what it’s complaining about?

Why does this matter? Because every time you have to read test code, you lose precious time. The feedback cycle lengthens, and you’re breaking your stride.​

Instead, I try to code using fast feedback. When I run unit tests and get a failure, I want to understand what I broke. And I want to do this without reading the test code. The test name alone can give you the information you need.

In this post, I’ll describe the unit test naming pattern that can give you feedback from the name alone.

What’s in a name? — Romeo and Juliet, Act 2, Scene 2
Continue reading

How Remote Mob Programming Is Working for Me


Ever since I experienced mob programming, it became my primary teaching tool. But due to COVID-19, it’s suddenly time for me to support remote workshops. Can mob programming work remotely?

To date, I’ve taught over 230 students about unit testing and Test-Driven Development. Almost all has been in person, with everyone in one room.

My last TDD for iOS workshop was going to be in Amsterdam. But with the unfolding health crisis, my host Jeroen Leenarts and I decided to make the workshop fully remote. I’d been intending to start remote workshops some day, but this forced my hand.

In this post, I want to share how my remote mob programming is evolving. And you can add your own ideas.

Continue reading

Learning Kotlin Showed Me the Truth About Xcode


In my first-ever live stream, I used a TDD exercise to learn the basics of Kotlin. In this recording, you can watch as I let the IDE guide me, stumble through mistakes, and get help from viewers. You’ll get to see how much better a good IDE can be than what we experience with Xcode.

Aside from learning Kotlin itself, I experienced two big things. First, it showed me that with good tooling, Test-Driven Development is a nice way to learn a new language.

Second, I got to experience what it was like to do live coding on Twitch. This came about from talking with Ted Young, who broadcasts his test-driven coding nearly every day. Ted told why he does it and what he gets out of it. This gave me the courage to jump in and give it a whirl. With only a 5-minute warning that I was going live, I didn’t expect anyone to be watching. So it surprised me to have a couple of viewers jump in who helped guide me into Kotlin coding.

I don’t expect folks to watch the full 2 hours of me stumbling along. But let me give you some tips of ways this recording could be helpful to you. …Even if you’re a die-hard Swift programmer who would rather “be dead in a ditch” than learn Kotlin.

Continue reading

Kotlin icon

Kotlin! Got Any Interesting Language/Testing Tips for Me?


This week, I’m learning Kotlin. And what better way to learn a new language than by writing unit tests against the code?

What’s going on, you ask? Is the world coming to an end?

Continue reading

Emoji: Graduation Cap

Advanced TDD Workshop for iOS Developers — On Sale Now


Have you done a few TDD exercises, but wonder how to bring it to your actual production code? Are you doing TDD in production code, but only for the simplest business rules? Did you TDD something only to feel it went poorly, and left your code worse off? Then it sounds like you’re ready for an Advanced TDD class.

Continue reading

Emoji: Fearful Face

Don’t Give Up on TDD Before Reaching Your Breakthrough


Dan Abramov recently tweeted:

That’s the beginning of a thread, so there’s more to it. But it gives me a chance to say to Dan, and the many folks who’ve shared this: You can still grow in Test-Driven Development. (Heck, I’m still growing.)

But instead of short tweets commenting on other short tweets, I thought I’d reply here. There’s room to discuss the gray areas.

Continue reading

Emoji: Check Mark Button

Refactoring: How Do You Clean a Mess, Safely?


Refactoring is moving in small steps, with each step verified by unit tests. As I demonstrated last time, these steps are much smaller than most people are used to. Let’s continue the same example to learn some new things about refactoring.

Reading is not as good as doing. I learned from the folks at Big Nerd Ranch that our brains make important connections when we type code. Download my code and walk through the refactoring steps yourself.

Continue reading

Emoji: Magnifying Glass

When You Refactor, Are You Using Small Steps?


Refactoring remains a much-misunderstood discipline. Even when folks do have unit tests to back their changes, how long does the code stay broken? Let’s return to the idea that refactoring happens in very small steps.

No, even smaller than that.

Continue reading

Emoji: Dice

Why Is Random Order a Big Deal for Test Quality?


Have you ever seen a unit test pass in isolation, but fail when run in a suite? Or vice versa, pass in a suite, but fail when run in isolation?

Besides the other improvements for test-centric workflows, Xcode 10 brought a rarity: a new XCTest feature for unit tests! Randomizing test order will help us flush out mistakes in the design of our tests.

Let’s start by examining a symptom… Have you ever seen naming like this in a test suite?

func test01RunThisTestFirst() { … }

func testCheckSomethingElse() { … }

This is a dirty trick to get the top test to run first, before any other tests in the suite. It relies on the fact that currently, tests within a suite run in lexicographic order. 01 comes early in ASCII, so test01RunThisTestFirst will run first.

Continue reading

Xcode beta

Joy! Xcode 10 Promises to Improve Test-Centric Workflows


Every WWDC, I hope for improvements to unit testing — but have learned to expect disappointment. So at WWDC 2018, I was surprised to have my low expectations thwarted! Xcode 10 brings changes that will improve my test-centric workflow.

For several years, Apple’s changes for test support have underwhelmed me. They focused on:

  • Xcode Bots (…I tried them. I gave up.)
  • Performance tests (…My code is not performance-critical.)
  • UI tests (…I don’t write any.)

With Test-Driven Development, unit tests run locally are my primary tool. The features above may have helped some people, but I wasn’t one of them.

So what did WWDC 2018 bring me? Here’s what I see on the horizon with Xcode 10.

Continue reading

Emoji: Rescue Worker’s Helmet

Do You Refactor without Tests? It’s Time for Safety


When you refactor, do you have unit tests covering you? …If not, why not? …If so, how do you know?

To me, it seems that the state of refactoring has gotten worse across the industry. Both managers and programmers and managers say the word “refactoring” more than ever. But they almost always mean, “I’m going to change a bunch of stuff. Then at the end, we need to make sure I didn’t break anything.”

But that’s not refactoring. That’s rewriting.

Continue reading

Emoji: Speech Balloon

How to Improve Code Comments with Little Refactorings


Does your code have comments? Sometimes they’re helpful. But most of the time…

Disclosure: The book links below are affiliate links. If you buy anything, I earn a commission, at no extra cost to you.

As Jeff Atwood explains, code tells you how, comments tell you why. A well-placed code comment is a level above the code itself, explaining why something is written the way it is. But! We can express most comments as code, using well-named identifiers. The first edition of  the Refactoring book called this Introduce Explaining Variable. Martin Fowler has since renamed that refactoring to Extract Variable.

Continue reading

Emoji: Nose

How Many Code Smells Can You See in This Short Method?


It’s time for a quick exercise in code smells!

How many code smells do you see below?

Continue reading

The 3 Laws of TDD: Focus on One Thing at a Time


When I was first learning TDD, I’d try to get to the First Step (a failing test) by writing a fully-formed test. But it often took a lot fiddling to get that test to run and fail. Sometimes this was because the production code took several steps to set up. Sometimes it was because the test code wasn’t right.

One of the tricky parts of TDD is that we’re creating two streams of code in parallel: the test code, and the production code. Two things changing at the same time… that’s a hard thing to keep in your head!

Continue reading

1 2 3 9