Friday, August 19, 2011

OCMock observerMock and unrecognized selector


I've been writing lots of unit tests for some new classes that use process wide NSNotifications.  I wanted to test these since I have not written NSNotification code often and this is a base class that a lot of future code is going to be built upon.

A handy way to test these are to use OCUnit with OCMock to create mock observers to verify that your notifications are being called.  Many others have talked about how to setup OCUnit, OCMock, and do Unit Testing in Xcode so I won't go there.

One article that did help me out with the OCMock observerMock usage was Alex Vollmer's Making Fun of Things with OCMock.  I used his example to build upon to write my mock observer tests.

I did run into a problem though while testing.  A test for a notification, let's call it MyCoolNotification, would pass and then a second test that tested this notification would fail.  The weird thing if I would see failures like:
  • [NSCFString handleNotification:]: unrecognized selector ...
  • [NSCFNumber handleNotification:]: unrecognized selector ...
These failures would be for the same call, same line of the test, but on different runs I would get different classes throwing exceptions due to the unrecognized selector.  What to do?

I put it together when I noticed the pattern, that the first test of usage of MyCoolNotification would pass but the second and remaining would fail.

The examples of the usage of [OCMockObject observerMock] left out one important NSNotification item.  Once you finish your test, don't forget to remove your mock from observing the notification.

Here is a more complete example of that I am talking about:
- (void)test_MyCoolNotification {
  id mock = [OCMockObject observerMock];
  [[NSNotificationCenter defaultCenter] addMockObserver:mock
                                                   name:MyCoolNotification
                                                 object:nil];
                                               
  [[mock expect] notificationWithName:MyCoolNotification object:[OCMArg any] userInfo:[OCMArg any]];

  MyCoolClass *coolio = [MyCoolClass create];
  [coolio someMethodThatFiresMyCoolNotification];

  [[NSNotificationCenter defaultCenter] removeObserver:mock];
  [mock verify];
}

By adding the removal of the object from the NSNotificationCenter you can now test the notification multiple times in multiple tests.

Saturday, March 5, 2011

TextMate

Holy Preview Update Batman!!

I have new respect for TextMate. I had the web preview open and I made a change to some javascript (switching the username from a sample user to my username) and the preview updated immediately to show me the changes.

Slick and very handy for editing this web app.

Thursday, March 3, 2011

PlayBook App

Well, my first PlayBook app is in development. I am going to write it using the BlackBerry WebWorks SDK which boils down to; I am writing a web app. I don't know the latest web technologies to save my life so this should be a good experiment to see how easy it is to develop something.

I've found two Javascript libraries to help me along the way and handle a large portion of the work I need for this app. Now I just need to do the gluing and get to work on getting something running in two weeks.

I will be doing a PlayBook Hackathon in 2 weeks and I want to be able to demo the app at the end of the event so I am taking my experience from my last Hackathon and going into this one with the basics of the app laid out. Then at the Hackathon I can get some advice on any areas that are giving me trouble.

Expect some further posts as I progress and once I get the demo completed.

Sunday, February 20, 2011

Preparing For Sale

Been a crazy weekend. In the last 24hrs I have been violently ill with food poisoning, picked up paint supplies for our painter that start yesterday, and filled one side of my garage with stuff to give away or throw out.

Just another fun filled day getting ready to leave my frozen homeland for milder climes in Washington state.

The house prep work is going well. Selling a house is probably easier in a sense when you are also moving to a new city, country, job (for my wife), and need to down size what you are taking with you.

Part of our big move is that we must inventory everything we own and assign a replacement value to it. This is for insurance purposes. Hence, you can tell that we are motivated to count less and throw out more. I mean really, if I have not used some of this stuff since we moved in here 6 years ago, is there really a chance I am going to be needing it when we settle in our new home? Nope, thought not.

Our first house showing to a prospective buyer is tomorrow. This came about due to word of mouth which is cool. Let's hope the fact our house is in a shambles since half of it is in a state of being painted, just painted, or about to be painted.

At least the house is clean and less cluttered by the minute.

Friday, January 21, 2011

HackOTT: A BlackBerry PlayBook App

What is HackOTT?


Hack Ottawa = HackOTT is part of the HackDays across Canada. Here's how it works:


  • Gather developers
  • Provide food, space to work, and APIs (Application Programming Interfaces, the building blocks for applications that programmers use to like you know, build stuff)
  • Let them code for 8 hours.
  • Judge the results

Read more here: http://hackdays.ca/2011/01/hack-ottawa-is-here/


Register Here: http://guestlistapp.com/events/42672


I've signed up for the event here in Ottawa and am starting to prep for the event. So, let's get down to the title tagline of this post: A BlackBerry PlayBook App.


If you don't know, I work for Research In Motion, better known as RIM. The RIM tablet offering is the PlayBook and it's coming soon. Being a geek, lover of new tech, and always in pursuit of a challenge; I've decided I'll design my app to run on the PlayBook.


Dude a PlayBook, Like Let Me See It


"Cool, Mark, you've got a PlayBook to use already? They aren't even for sale yet," you say. Well, the truth is I don't have a PlayBook and if I did I would not be bringing it out to play. So, don't expect me to be toting one around to show you and demo. I have to wait for them to be available for sale like everyone else.


Well then how am I going to develop for the PlayBook? With the dev tools including the BlackBerry Tablet SDK and the BlackBerry Tablet Simulator for VMware Fusion; on my Mac Book Pro of course. All further discussion is specific to programming on the Mac. If you are a Windows dev, sorry, this might be of little use to you.


Setting Up A New Project


Let's jump in and get started.

BlackBerry PlayBook Resources


Ok, got that done? Good. Let's drop a couple links to resources to help you along the way of coding up your BlackBerry PlayBook App.

Ok, that's all for tonight. Next, I'll be reading up on the WebWorks SDK and the Adobe AIR SDK to see which one I'd like to use for the project.

Friday, June 18, 2010

Nintendo Jumps the Shark?

If you don't know by now, Nintendo made the surprise announcement of a new Goldeneye game rebooted (as they call it) for the Wii. Since it is 2010 and Pierce Brosnan is no longer James Bond, they have redone the game with Daniel Craig.

Now don't get me wrong. I love James Bond. I think Daniel Craig is an excellent Bond.

But Nintendo, how bad are things when you have to reboot not the franchise but one of the best first person party shooters of all-Nintendo time?

I look forward to seeing and playing the game but Nintendo you have big shoes to fill rebooting Goldeneye. If you can pull it off excellent. If it is a dud, has Nintendo jumped the shark?

Sunday, February 7, 2010

HockeyTweet 1.2 Now Available in the App Store

HockeyTweet version 1.2 is now available in the Apple App Store. This is a minor release which fixes a change to Twitter's OAuth system used for user authentication.

You can download the upload today if you are already a user. Enjoy!