13 posts with this tag

Black and white box unit testing techniques

August 09, 2012

If you have ever written a unit test, chance has it that you used either black or white box testing techniques to determine what that unit test was testing. In this post I want to explore both these techniques and look at when we should be using them. Black-box techniques Black-box testing is were we use the contract (api) and/or a functional specification of a method to determine how to test it. We can think of this as testing the method's inputs and outputs. It requires us to look at the various possib…

The benefits of unit testing

June 16, 2012

I find it surprisingly hard to get new developers to really engage with unit testing but then when I think back to when I had just graduated and what I thought about unit testing: I'm here to write code, not to test! I shouldn't be surprised. Unit testing works slightly counter intuitively - by undertaking additional work (writing unit tests) we can actually save having to perform additional work (fixing bugs) and so speed up overall development. This speed increase is only one benefit, below I want to g…

A walkthrough of testing a class

June 01, 2012

iOS hasn't always been the most unit-test friendly environment, but since Xcode 4 this has changed - a lot of the setup has now been automated away for us. These improvements make adding unit tests to your application easier than ever. However, the question remains: What should be tested? What needs to be tested? There is no generic answer to that question instead it always needs to be answered in the context of an example: .h typedef NS_ENUM(NSUInteger, UTEPersonGender) { UTEPersonGenderMale = 0,…

Test only what you need to work

May 18, 2012

Bugs only exist in software because we as developers introduce them. We don't mean to introduce them however there is no denying that they exist and that we've all come across them at some point in the software that we use. Thankfully there are a range of testing techniques that we can employ to ensure that the code that we produce is as bug free as is possible given the time that we have. The software development process is a much used phrase that describes the different parts involved in creating an appl…

Hide behind your interface

January 06, 2012

When writing a class or method, the way that I view other classes that want to use my class is as my enemies (even if I’m writing the other classes!). That might should dramatic but I take the approach that what ever is going to use my class might not properly understand the class and feed it junk. Proper encapsulation and information hiding can help us achieve this. Often encapsulation and information hiding are used interchangeably however they are two independent ideas. Encapsulation Is the mechanism…

Defending your Datamodel classes

November 28, 2010

On a project recently I had to develop some model classes that would be populated upon creation from a web service. A requirement was that once the model object where created they should not be altered. As I wasn't the sole coder on this project I decided to defend these objects and ensure that their properties were indeed read-only. Objective-C doesn't lend itself to strong encapsulation due its dynamic nature so I had to think outside the box. I decided on using private instance variables with read-onl…