Re: problem unit testing core data
Re: problem unit testing core data
- Subject: Re: problem unit testing core data
- From: Jesse Grosjean <email@hidden>
- Date: Wed, 26 Oct 2005 11:45:10 -0400
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.
I think I'm retaining the document in the setup method, it is tacked
onto the end of this line:
document = [[[NSDocumentController sharedDocumentController]
openNewDocumentAndSaveAs:[NSURL fileURLWithPath:path] display:NO
error:nil] retain];
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.
I've just tried retaining the document controller and it doesn't seem
to make any difference. By the way, when running unit tests there
isn't any run loop setup? I'm pretty certain that's the case, and
probably at the root of my problem.
In this case, there is no need to call release in the teardown method.
The tests will run without error if I do this. But this is because
I'm leaking the document variable for each test case since the retain
call in the setUp method is not balanced. This is nice because I can
run my tests, but it's a bit messy and just avoids the problem
because nothing is ever dealloced.
Outside of unit testing, you do need to specifically retain such
objects if you hold their value across event loops.
Sorry if I'm not understanding your suggestions exactly, but I'm
fairly certain it's not a retain/release issue with the document. The
document isn't getting over released, the error is thrown as the
document and it's managed object context are being dealloced.
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