Re: Xcode and WOUnitTest 2
Re: Xcode and WOUnitTest 2
- Subject: Re: Xcode and WOUnitTest 2
- From: Christian Pekeler <email@hidden>
- Date: Thu, 7 Dec 2006 09:28:54 -0700
EOEnterpriseObjectClazz.objectWithPrimaryKeyValue(ec, pk);
or
EOUtilities.objectWithPrimaryKeyValue(ec, entity, pk);
These methods create qualifiers against primary key attribute which
is not selected as a class property in model.
Why do you fetch objects by their primary key? I don't mean to sound
condescending, but I don't think I've ever had to do this in my 8
years of working with WO.
Anyways, the MockEditingContext is meant for testing in memory. It
can't handle hard-coded sql, raw rows, or access to non-property
attributes. One way around this is to factor out any such code into
extra methods and stub them out for unit testing. For example:
public class Blah {
public String foo() {
...
... someEO();
...
}
protected SomeEO someEO() {
return (SomeEO)EOUtilities.objectWithPrimaryKeyValue(...);
}
}
public class BlahTest {
static class TestBlah extends Blah {
SomeEO someEO;
@Override
protected SomeEO someEO() {
return someEO;
}
}
@Test
public void foo() {
TestBlah blah = new TestBlah();
blah.someEO = mockEditingContext().createSavedObject(SomeEO.class);
assertEquals("...", blah.foo());
}
}
Christian
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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