Re: JUnit for testing EOs
Re: JUnit for testing EOs
- Subject: Re: JUnit for testing EOs
- From: Chuck Hill <email@hidden>
- Date: Tue, 27 Nov 2007 19:03:30 -0800
I don't think you should _need_ to do this as long as the bundles are
correctly formed and on the classpath as they would be at app
runtime. I don't have this in my tests and I am using EOF. What I do
have is the usual prototype switching and connection dictionary
changing code.
You may need to do something like this to jump start things:
NSBundle.allBundles();
EOModelGroup.defaultGroup();
Chuck
On Nov 27, 2007, at 5:19 PM, Sam Barnum wrote:
I usually need to manually create the EOModel for test cases.
Programatically load the model into the default ModelGroup, like so:
static { try { EOModel model = new EOModel(new File("Web/Resources/
MyProject.eomodeld").toURI().toURL()); EOModelGroup.defaultGroup
().addModel(model); } catch (MalformedURLException e) { throw new
RuntimeException("Couldn't load EOModel", e); } } Note that the
model is loaded using a file with a relative path to the model
file, from the project root. We call File.toURI().toURL() because
File.toURL() is deprecated (it doesn't convert spaces correctly)
After doing the above you should be able to create a new editing
context and create entity instances normally.--
Sam Barnum
360 Works
http://www.360works.com
415.865.0952
On Nov 27, 2007, at 2:00 AM, Paul Hoadley wrote:
Hi Chuck,
On 27/11/2007, at 5:04 PM, Chuck Hill wrote:
Add it to User Entries. It also needs to go above the other
entries in the class path. If the model (or any other
resource) is in a framework, you also need to add the Resources/
Java dir for that to User Entries above the default stuff.
Hmm, well AFAICS I've done that:
<pastedGraphic.png>
Yes, that looks correct. Can you take a look in /AM/build/AM.woa/
Contents/Resources to ensure the eomodel is in there and has the
entities.
Certainly seems to be. Here's one of the eomodels and its entities:
<pastedGraphic.png>
Something also may have changed in WO. I have a rather, er,
funky build setup and run the Ant builder at each build. So I
always have a properly formed framework. If you are using the
incremental builder (as most people are), the problem might be
related to this.
I presume I am, if most people are. I've done nothing but install
Eclipse, WOLips, WO5.4 and start some projects.
I don't think so, but it might be. It is definitely related to
NSBundle resource loading and NSBundle is very path sensitive.
The models are not in frameworks. I am still getting "Unabled
[sic!] to find an EOClassDescription".
I love that error message. :-)
Hmmm, just registered that this is an application. I never (or
darn rarely) unit test apps.
Oh OK. Although I've used JUnit before in a different context, I
really am just trying to bootstrap myself up from zero here. If
there's a better way, by all means correct me! All I've done so
far is written a single test class with the intention of testing a
single entity class (which actually refers to two others, so three
in total). They're all in the same Auth.eomodel up there. So if
it looks like I'm trying to unit test the app, that's
unintentional. How do I just test a class from a single model?
Does adding /AM/build/AM.woa/Contents/ to the build path help?
Try making that the working directory on the arguments tab.
If this looks right, then no, it didn't help. :-)
<pastedGraphic.png>
(As an aside, do I need to go through this for every single
test class I create?)
Not sure what you are doing there... I create a
"AllTestsSuite.java" for each project and have that instantiate
the test classes. So I only need to set up the launcher once
for each project, for AllTestsSuite. Does that make sense?
Yes it does. I'm also pretty new to JUnit, and was just trying
to get a single test class going.
To be honest, I'm not wedded to the idea of JUnit. If TestNG is
simpler to get going, I'll go take a look at that instead.
It is not going to fix this NSBundle finding its resources issue.
Well, I'm happy to press on if you and the list can be bothered
remotely debugging this. :-)
--
Paul.
w http://logicsquad.net/
h http://paul.hoadley.name/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40360works.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40global-village.net
This email sent to email@hidden
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden