Boundary value analysis for bug fixing

Anyone who has worked in quality assurance or is serious about testing knows about a technique used to define test cases that is called boundary value analysis. Here is how Wikipedia describes it:

Boundary value analysis is a software testing technique in which tests are designed to include representatives of boundary values. […] Since these boundaries are common locations for errors that result in software faults they are frequently exercised in test cases.

In short: faults like boundaries.

This principle has been of great help to me lately when investigating about a curious bug that affected a customer of mine, and, what’s more, only one of its iPads. It was a nasty bug, of the kind that is not easily reproducible but keeps popping up from time to time.
Usually what you do in such cases is asking the customer for trace logs, or, if none is available, ask her to describe how she got there and so on, in an effort to shed some light on the apparent randomness of that behavior. This approach only rarely succeeds, unfortunately, due to a multiplicity of factors (logs are not meaningful or not available, the customer is not able to describe correctly what she did and so on).

In such cases, which usually lead close to despair and to many hours sitting in front of a monitor in frustration, code review is really the only way to go. Still, in the face of a “perfect” code, where you can find no evident problem, what you really need is some criteria to guide your search. This is where boundary value analysis comes into the picture.

If you like details, to better grasp the situation I am describing, here they are: the app was a simple, animated, CSS3 clock; its main feature was it’s unique, copyrighted design, that you can appreciate below, and it sported a continuous shift of the hands and some specific lightning to reproduce a realistic shadow effect of the clock hands against the background. What happened is that sometimes, launching the app, the seconds hand shadow, and only that, behaved in a crazy way. All of the other clock hands and their shadows continued to work correctly.


What was really striking at that was that all the three hands and their shadows used the same CSS3 animation; so why, in the first place, just one was not working. So this had to do with the specific position of the seconds hand shadow at the moment when the animation started, but, even more puzzling, that was exactly the same initial position of the seconds hands. And this one was always working smoothly. I was really lost.

When I started to review my code, I immediately noticed that there were indeed a few boundaries I could inspect. The animation was defined in terms of an interpolated rotation across four cardinal points. At each cardinal point, specified by its angle, the position of the clock hand and its shadow was defined in terms of rotation and translation respect to the 12-o’clock normal position.

Based on this, I designed a test to stress the animation when the starting time was close to those cardinal points. The test repeatedly started the animation by progressively advancing the start time a bit. It turns out that this approach was right, since it quickly showed that there was a tiny interval around one of those cardinal points where the seconds hand and its shadow were almost overlapped; almost: their distance was close to zero and definitely negligible, but definitely not zero (think 1.0e-16). This led to a number which was not proper CSS3, so the animation failed.

Rounding that tiny number to zero fixed the bug.

Summing things up: when the only resort you have to try and find a nasty bug is code review, boundary value analysis can be your valuable friend.

cocos2d and the new retina iPad - take 2

I described in a previous post about cocos2d and the new retina iPad a quick solution to the problem of supporting higher-resolution images. The main objective of that work was to make easier re-building your app for submission on the App Store before  you could possibly provide higher-resolution images for the new iPad. I mentioned anyway that that approach was just a quick hack and not  a full answer to the need to provide 4 (four!) different versions for any of your artworks.

Playing a secondary theme in Cocos2D

Cocos2D offers CocosDenshion, an easy to use framework to work with audio.

iOS6: dynamic autorotation

One of the most intrusive changes brought by iOS6 is the way autorotation is handled in UIViewControllers. If you have an autorotating app for iOS5, you will need to change it to correctly support autorotation under iOS6. If you develop an app which is supposed to run both on iOS5 and iOS6, then you will have to handle autorotation in the old as well as the new way.

Hitchhiker's guide to MKStoreKit

In-App Purchase is one of those great feature of the iOS ecosystem that I wish were easier to understand and implement in my apps. In the end it is just a machinery that will not really add value to my apps, and it would be great if the Apple motto “it just works” could be applied to StoreKit as well.