Category Archives for iOS Tools

Why Is Random Test Order a Big Deal for Test Quality?

Shares

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 brings 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

Joy! Xcode 10 Promises to Improve Test-Centric Workflows

Shares

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

How to Use SwiftLint for Clean, Idiomatic Swift

Shares

We get feedback from the compiler. We get feedback from Test-Driven Development. But what sources of feedback lie in between?

This is where linters come in. A linter goes beyond “Does the code compile?” A linter answers questions like, “Is the code idiomatic? Is it stylistically clean? Are there any red flags?”

Continue reading

Automatically Generate Swift tearDown with This AppCode Plugin

Shares

Those of you who are regular visitors to qualitycoding.org may have already read Jon’s article outlining the life cycle of XCTestCase objects during the execution of a test suite. If you haven’t, or you want to refresh your memory, take a moment to read the original article.

Jon discusses the importance of the setUp and tearDown methods. And, more specifically, why we should be deallocating our properties in the tearDown method.

Writing a tear down method is one of those repetitive tasks. It follows a specific pattern: all properties should be set to nil. It doesn’t really require any brain power. It’s just one of those annoying tasks that you have to remember to do when writing a test.

It’s tasks like this that should be automated. And now with the Swift tear down inspection AppCode plugin, we can.

Continue reading

What Are Your Favorite Tools for Productive Programming?

Shares

I’m always on the lookout for new tools. Are you? Anything that might increase programmer productivity is worth a look.

You know that I’m a big AppCode fan. It saves huge amounts of time. And doing so within an IDE helps me stay “in the zone.”

I’ve shared about 6 Simple Power Tools for Better Git Use. Thanks to reader comments, I learned about Oh-My-Zsh for command-line, and SourceTree for GUI. AppCode also provides great Git support.

So I’d love to hear more from you. What are your favorite tools for productive programming? Share your tips in the comments below!

Dr. Seuss Matching Game

How to Make Your Own OCHamcrest Matcher for Powerful Asserts

Shares

OCHamcrest matchers are predicates on steroids:

  • You can combine them to create expressive assertions.
  • They describe mismatches in detail, reducing the need to debug.

But OCHamcrest isn’t just a library of powerful matchers. It’s a framework for creating your own.

By creating a custom matcher, you create a small Domain-Specific Language. This will make your unit tests easier to write, easier to read, and self-diagnosing!

Continue reading

AppCode vs. Xcode Unit Testing Battle

Share

AppCode vs. Xcode: Which is easier to use for unit testing? Which gives better feedback?

I’ve written about the big improvements to OCMockito’s error reporting. But when I ran the tests, I saw striking differences between the two IDEs.

Continue reading

The Swift Unit Testing Template You’re Missing

Shares

Back in Xcode 4 days, Apple’s file template for Objective-C unit tests was awkward and bloated. So I made my own.

Fast-forward 5 years to Xcode 7.3. I’m starting to write Swift. The first thing I want is unit tests — let’s create a new test suite.

Why am I not surprised that Apple’s template for Swift unit tests is filled with cruft?

Fine. I made my own.

Continue reading

crash test dummies

Can OCMockito’s New Error Reporting Save You Time?

Shares

Fast feedback is the chief benefit of TDD. Even if you’re not practicing TDD, anything that reduces the need to step through code saves a lot of time. For example, if you name your tests well, a test failure can tell you a lot just from the test’s name.

But what if you’re using a mock object? When a test fails, what can it tell you?

A hand-coded mock can tell you as much as you can code. But writing boilerplate gets old, so the reporting tends to be shallow.

And most mock object frameworks generate mocks that simply report, “Such-and-such was not invoked.”

This was also true of OCMockito. Until recently. Here are the 3 new descriptions of verification failures:

Continue reading

7 Cool AppCode Features that Support TDD

Shares

We’re pair programming, with you driving. You’re using Xcode.

I don’t say anything because I don’t want to offend you. But you’re having to do So. Much. Typing.

They say typing isn’t the slowest part of programming. But as I sit with you, I wonder… Why isn’t the code automatically appearing? We’re on a computer working in a computer language, so why doesn’t the IDE understand your intent? Why do you have to make the same changes in so many places?

Oh yeah. You’re using Xcode.

Continue reading

>