Testing persistence frameworks that use subclassing

29 views
Skip to first unread message

Liron Yahdav

unread,
Aug 22, 2015, 4:46:50 PM8/22/15
to Growing Object-Oriented Software
I'm an iOS developer and we use Core Data as our persistence framework in our app. In Core Data your domain models are classes that subclass a specific class (called NSManagedObject).

I've read chapter 25 (Testing Persistence) of GOOS and it seemed to be Customer class in that chapter is a POJO (plain old java object).

My question is this:
Does it make sense when using such persistence frameworks that require subclassing to create your own plain Customer class that doesn't inherit from anything and then to build mapping logic between your persistence class (e.g. PersistedCustomer which is a subclass of NSManagedObject) and your application domain class (Customer)?
Or if your PersistedCustomer happens to have the interface you actually want, perhaps have Customer be an interface that PersistedCustomer implements? With this approach would tests that use Customer then create a mock customer (since it's an interface)? Does it matter you're not creating concrete Customer objects in tests? Obviously you wouldn't want your business logic tests to be instantiating PersistedCustomer objects since that requires you to bring in the entire persistence framework into your tests. Another approach here would be to create an implementation of the Customer interface that's only used for tests, but it seems strange to create a class like that specifically for tests.

solomon....@gmail.com

unread,
Aug 23, 2015, 9:33:38 AM8/23/15
to growing-object-o...@googlegroups.com
While you do have to bring the whole persistence stack into your tests, you can create a managed object context that uses an in memory store so your tests will at least be fast integration-ish tests. Depending on your dev plans it might make sense to have an adapter layer to transition posos into core data types but it might be over kill to do that. 

Sent from my iPhone
--

---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriente...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages