Categories
mobile Programming

Android: Testing an Intent Service

There’s a handy thing in Espresso called the ServiceTestRule, which is for testing Services. Yay. I thought it was just what I needed until I read this bit of the documentation… OK, first up – refactoring my IntentService. This class already did very little, poking something else depending on the kind of Intent it received, and […]

Categories
Programming

Testing Intents on Android: Like Stabbing Yourself in the Eye With A Blunt Implement

The picture above shows what am I testing: the home screen of my app. There is a camera button, a gallery button and an inspire button. All of these launch intents, but the camera and gallery buttons launch intents that are expected to return something – an image – either from the camera or the […]

Categories
Programming

OCMock and Values

OCMock is mostly great! And I use it a lot! But there’s one problem with it – handling values. I was debugging some asynchronous tests and having this problem, which I assumed at first came from the asynchronicity but it turns out, no, it’s just CGFloat being CGFloat. Clue for this kind of bug is […]

Categories
Programming

Replacing KIF Tests with XCUI Tests

I thought about doing this in Swift but decided to take this one thing at a time (I haven’t written any Swift yet). My strategy: 1) get tests working and then 2) convert them to Swift. This post focuses on (1). As for what tests to write, I had a full suite of KIF tests […]

Categories
Programming

A Brief Rant about TDD

I’ve been giving this talk about unit testing UI code lately and of course when you talk about testing, TDD (test driven development) keeps coming up. The question ranges from “have you embraced TDD as the One True Way Of Testing, and if not why not because you’re doing it wrong” and “I have heard that […]

Categories
Programming

Unit Testing on iOS

Historically, there hasn’t been a lot of testing done on iOS, and we see the results of that every day—regressions, crashes, consistently reproducible failures. As we build more complex applications, manual testing takes more and more time and automated testing becomes increasingly necessary. The biggest challenge of testing on iOS starts at the UIViewController with […]

Categories
Programming

Some Thoughts on Mocking

    When do we use mocks and when shouldn’t we? Some thoughts: Don’t Mock Data Structures We wouldn’t mock an NSArray or an NSDictionary, so why would we mock our own data structures? Data structures should be simple and well tested, so we can trust them to behave as they should. It will be […]

Categories
mobile Programming

Launching! iOS Unit Testing: Beyond the Model

I’m super excited to release something that I’ve been working on for a while. Unit testing on iOS is… not common. And part of the problem is that people don’t know where to start. It can be overwhelming. Building on my years of experience leading iOS apps with over 80% test coverage, including at Google, […]

Categories
mobile Programming

Creating and Comparing Images on Android

A while ago, I wrote this blog post on creating and comparing UIImages. That code allowed me to develop the image processing part of the app against my unit tests, which was really, really helpful given that I rewrote it about four times to make it performant enough. So, when I started writing Android code […]

Categories
Programming

Four Reasons Unit Testing Needn’t Be That Time-Consuming

On my mind this week because I’m giving a workshop and a talk on unit testing UI code on iOS. Tests as Documentation. You think you remember what you did and why… but you don’t. Replace debugging. I almost never use the debugger. If something isn’t working as expected, I just start writing tests and figuring out […]