Re: Test Cases + Nib files
Re: Test Cases + Nib files
- Subject: Re: Test Cases + Nib files
- From: Chris Hanson <email@hidden>
- Date: Tue, 13 Nov 2007 15:08:26 -0800
On Nov 13, 2007, at 10:03 AM, Jacob Portukalian wrote:
I am writing a game in which I am creating some custom view classes
and I want to create test cases where I verify that the behavior of
these classes is "as advertised."
First off, it'll be helpful to tell us what version of Mac OS X and
what version of Xcode you're using. It matters.
Is there a way to add nib files to a test case bundle? Or do I need
to create a new target? I created a new target, then a nib file that
I added to that target, but I get the following message when I build
+run it: "Error from Debugger: No executable file specified."
You can just add your nib files as members of your test bundle. When
you load them, of course, you'll want to load them from the test
bundle's resources rather than from the main bundle's resources.
For example, you can very easily write a test case like the following,
and test a nib whose File's Owner is an instance of NSViewController:
// MyTestCase.h
#import <Cocoa/Cocoa.h>
#import <SenTestingKit/SenTestingKit.h>
@interface MyTestCase : SenTestCase {
@private
NSViewController *viewController;
NSView *view;
}
@end
// MyTestCase.m
#import "MyTestCase.h"
@implementation MyTestCase
- (void)setUp {
[super setUp];
viewController = [[NSViewController alloc]
initWithNibName:@"MyTestNib" bundle:[NSBundle bundleForClass:[self
class]]];
view = [viewController view]; // owned by viewController
}
- (void)tearDown {
[viewController release];
view = nil; // owned by viewController
[super tearDown];
}
- (void)testInstantiation {
STAssertNotNil(viewController, @"Should be able to instantiate
the view controller with the nib 'MyTestNib' in the test bundle.");
}
@end
When I go into the Build/Release directory I find a bundle
"MatrixTestTarget" (the same name as my new target) but it will not
run (it has the circle with the line through it on the icon). Inside
the bundle there is no MacOS directory or executable anywhere.
Have you actually written any unit test code that is part of that
bundle?
I've written a series of weblog posts on using Xcode's unit testing
infrastructure that can be found here:
Chris Hanson tags: unit testing
http://chanson.livejournal.com/tag/unit+testing
I still need to post updated versions of the Debugging Cocoa Framework
Unit Tests and Debugging Cocoa Application Unit Tests articles, since
you need to add a couple of additional environment variables to debug
them. And to cover running tests for frameworks that require
Objective-C garbage collection.
Thanks in advance. I can't find any documentation on this stuff so
I'm blindly stabbing into the dark right now.
Xcode 2.1 and later do include a Unit Testing Guide which my weblog
posts supplement.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden