2

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:

  1. Use Realm/Headers in Podfile for Test targets and just Realm 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

  1. 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?

Sergey Katranuk
  • 1,162
  • 1
  • 13
  • 23

1 Answers1

1

While waiting for the reply, I managed to find an answer in this fine gentleman's blog post :)

  1. Make sure all your .swift files have Target Membership set only to your main target
  2. As I mentioned in the question, in your Podfile add Realm for main target and Realm/Headers in your test targets
  3. Check that all your test targets have Build Settings -> Product Module Name set to the same value as in your Main target
  4. Final and missing step in my case, add the following path $(CONFIGURATION_TEMP_DIR)/YourMainTargetName.build/DerivedSources in your test targets Build 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.

Community
  • 1
  • 1
Sergey Katranuk
  • 1,162
  • 1
  • 13
  • 23