• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Looking for tips on debugging with OCUnit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking for tips on debugging with OCUnit


  • Subject: Re: Looking for tips on debugging with OCUnit
  • From: Ryan Bates <email@hidden>
  • Date: Sun, 7 Mar 2004 14:49:08 -0800

Hi Mike,

The problem in your code is that the board's instance variables (spaces) are never established, and therefore, retrieving a space from the board will return a nil object. Inside you game board's "init" method, you should set each of the spaces to a space object, like this:

// Inside MZTicTacToeGameBoard.m
- (id)init
{
self = [super init];
if (self) {
space1 = [[MZTicTacToeSpace alloc] init];
space2 = [[MZTicTacToeSpace alloc] init];
// etc.
}
return self;
}

This method will be called upon creation of the game board, so it's a good spot to create all your spaces.

On a side not, if you are doing TDD (Test Driven Development), you may want to refactor while writing. A big part of refactoring is removing duplicate code. Creating a separate instance variable for each space is somewhat tedious, so I suggest using an array of some sort. If you want to learn more about refactoring, there is a great book by Martin Fowler called "Refactoring: Improving the Design of Existing Code." The examples are given in Java, but it just as much applies to Objective-C and is easy to translate.

Ryan


On Mar 7, 2004, at 12:49 PM, Mike Zornek wrote:

I have a project called TicTacToe that in time I hope will be a nice little
game. The main purpose of making it is for me to give OCUnit a good real
world test. I've gotten pretty far, building/installing the SenTestingKit
framework, working on the samples (ie: Person), and now even getting a good
number of tests under my belt on this new app -- but I've hit a wall.

http://mikezornek.com/temp/TicTacToe03072004.sit

I have two classes: MZTicTacToeGameBoard and MZTicTacToeSpace. The basic
idea is that each board has nine spaces, each space has a mark property
which can be "X, "O" or "". I wrote all of the tests for MZTicTacToeSpace,
implemented the code to pass the tests and then moved on to
MZTicTacToeGameBoard. I began to write some basic tests here but after doing
the implementation they still fail. I personally don't see why they are
failing and attempts to NSLog values out doesn't seem to work.

In general what are some good tips for finding bugs such as this one? And if
you have spotted mine please let me know.

Thanks,
~ Mike
-----
Mike Zornek
Web Designer, Media Developer, Programmer and Geek
Personal site: <http://MikeZornek.com>
New Project: <http://WebDevWiki.com>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Looking for tips on debugging with OCUnit (From: Mike Zornek <email@hidden>)

  • Prev by Date: Re: NSEditor, NSEditorRegistration Protocols
  • Next by Date: Re: Reloading a preference window settings
  • Previous by thread: Looking for tips on debugging with OCUnit
  • Next by thread: Using NSView as a template
  • Index(es):
    • Date
    • Thread