I hope this question is seen and answered by someone from the Realm team
I have a project that uses Cedar to write BDD style tests. I have a mixed project with Objective C and Swift files. Some of these swift files are for custom Realm models. I use CocoaPods to install Realm to my project.
The recommended settings that I've seen so far are the following:
- Use
Realm/Headers
in Podfile for Test targets and justRealm
for main target - this solves the+[RLMObjectBase ignoredProperties]: unrecognized selector sent to class
error.
My app builds and runs but now I get this RLMObject subclasses with the same name cannot be included twice in the same target
If I remove the swift objects from all of my test targets and leave them only on the main one, now I can't see them inside test files, which leads me to the next point
- Use @testable in your swift files. That's a good advice if you're testing with a swift XCTest class, but it doesn't work with Cedar (or I don't know how to make it work)
So my question would be, is there any way I could make this setup work? What would be the exact steps?
While waiting for the reply, I managed to find an answer in this fine gentleman's blog post :)
Realm
for main target andRealm/Headers
in your test targetsBuild Settings -> Product Module Name
set to the same value as in your Main target$(CONFIGURATION_TEMP_DIR)/YourMainTargetName.build/DerivedSources
in your test targetsBuild Settings -> Header Search Paths
Do the final step for each test target, if you have multiple, and for each build configuration (ex: Alpha, Beta, Release) if you have multiple.
This also gives us the nice benefit of removing swift classes' membership from our test targets (just like for our Objective-C classes).
Now your tests should run, and Realm shouldn't throw exceptions at you.