Re: problem unit testing core data
Re: problem unit testing core data
- Subject: Re: problem unit testing core data
- From: Tim Hart <email@hidden>
- Date: Wed, 26 Oct 2005 10:04:07 -0500
On Wednesday, October 26, 2005, at 09:52AM, Jesse Grosjean <email@hidden> wrote:
You do not retain a copy of the document variable in your setup routine, yet you release it in your teardown routine. That's the problem.
Since you were not responsible for creating the document controller, you must purposefully retain it in the setup if you need to retain it across event loops.
In this case, there is no need to call release in the teardown method.
Outside of unit testing, you do need to specifically retain such objects if you hold their value across event loops.
Tim Hart
>I'm seeing the following error when I run unit tests on my
>NSPersistentDocument based application:
>
>2005-10-26 08:53:18.068 otest[19257] *** -[NSAutoreleasePool
>dealloc]: Exception ignored while releasing an object in an
>autorelease pool: The NSManagedObject with ID:0x346e060 <x-coredata://
>FD637DAE-68F9-4B0B-BC4F-7646659C9C4A/ContentIndex/p114> has been
>invalidated.
>
>The error occurs after running each test case as the auto-release
>pool for that test case is released, then the otest tool crashes
>after running all of the tests. Here's some more notes on what's
>going on, please let me know if you have ideas on where I'm going
>wrong or thoughts on getting around the problem. Here's my setUp and
>tearDown methods:
>
>- (void)setUp {
> NSString *path = [NSTemporaryDirectory()
>stringByAppendingPathComponent:@"test.mydocument"];
> [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
>
> // openNewDocumentAndSaveAs: is a category method that calls
>makeUntitledDocumentOfType, adds to document to the document
>controller and saves
> // the new document at the given location.
> document = [[[NSDocumentController sharedDocumentController]
>openNewDocumentAndSaveAs:[NSURL fileURLWithPath:path] display:NO
>error:nil] retain];
>}
>
>- (void)tearDown {
> [document close];
> [[NSFileManager defaultManager] removeFileAtPath:[[[document
>fileURL] path] stringByDeletingLastPathComponent] handler:nil];
> [document release];
>}
>
>The exception is thrown as the managed object context is being
>dealloced (maybe somewhere in the private _dispose: method). It's
>important to note that when I run my application normally I see no
>errors when opening and closing documents and ObjectAlloc shows that
>objects are being created and released as expected.
>
>Does anyone know what might be the problem and how best to fix it?
>
>Thanks,
>Jesse
>
>
>
> _______________________________________________
>Do not post admin requests to the list. They will be ignored.
>Cocoa-dev mailing list (email@hidden)
>Help/Unsubscribe/Update your Subscription:
>
>This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden