• Master’s thesis introduction and summary now in Finnish and English

    I’ve posted the introduction and the summary of my Master’s thesis in both Finnish and English.

    Friday, January 23rd, 2009 at 01:11
  • Recording and validating NSNotifications in Objective-C Unit Tests

    Last week I had to write some unit tests for a class which sent NSNotifications to the default NSNotificationCenter. I wanted to make sure that the instance sent those notifications with correct names, with correct information and in correct order.

    The default NSNotificationCenter is basically a global context which is used by many classes. As Miško Hevery points out, global state makes testing hard. So if I decided to be pedantic about avoiding global state and making my code easily testable, I would create a new NSNotificationCenter in a factory and inject it into every class which needs it in each class’ init… method. Then, in unit tests, I could inject my own subclass of NSNotificationCenter which would receive all notifications sent by the instance under test. Then I could examine those notifications and make any checks I need. However, injecting NSNotificationCenter into each class which needs it complicates their init… methods, and it’s probably a bit overkill to require each class which is interested in notifications to retain a notificationcenter in an ivar.

    A bit more pragmatic way to record & validate notifications sent by the instance under test is to create a mutable array, register it as an observer of the instance in the default NSNotificationCenter, exercise the instance and then validate the notifications which were catched by the array. Fortunately, NSMutableArray has a method which can act directly as notification callback: the good old -(void)addObject:(id)anObject. For instance:

    MyClass *obj = [[[MyClass alloc] init] autorelease];
    NSMutableArray *notifications = [NSMutableArray array];
    
    [[NSNotificationCenter defaultCenter] addObserver:notifications
       selector:@selector(addObject:)
       name:nil
       object:obj];
    
    [obj exercise];
    
    STAssertEquals([notifications count], 1u,
       @"Invalid number of notifications.");
    STAssertEqualObjects([(NSNotification *)[notifications objectAtIndex:0] name],
       @"MyClassNotificationName", @"Notification name was invalid.");
    Monday, December 22nd, 2008 at 01:49
  • Master’s Thesis is done

    So, I’ve finally finished my Master’s Thesis in computer science. The subject of the thesis is Code reviews in a small software company and it’s available online for anyone who’s interested in code reviews. Thesis was graded as eximia cum laude approbatur. It’s written in Finnish, but I’m planning to translate the abstract to English in the near future.

    Tools which were used to write the thesis:

    I would like to express great gratitude to the company which took part in the case study of my thesis and which made the whole thesis possible - Marko Karppinen & Co. LLC. Great thanks go also to my instructors from the department of computer science for their great patience and efficiency especially during the extremely busy last week of the graduation process.

    So, one of the main goals of mine - the master’s degree - is now completed. My blog has now been offline for several years and I have decided to bring it back to life. This time I’ll keep the blog’s theme more focused - the main theme is software engineering, quality processes and Mac programming. I’ll also write in both languages - Finnish and English, and each post will be tagged by either “in-english” or “in-finnish” tag to allow easier browsing and filtering of posts.

    Writing about both abstract and concrete ideas forces one to think things through. In addition to the traditional learning by teaching effect writing publicly enables ideas to be peer-reviewed by other professionals and improved (or dismissed) via discussion.

    Wednesday, December 10th, 2008 at 20:47
TOP