I have looked at the post here How to unit test Realm migrations and am trying to implement what they have stated which is the following:
Store old .realm
files and write tests for before / after migrations.
I have my v0.realm
file in my unit test bundle and am creating a copy of it to work with. The issue is that with my latest migration I removed a Type from my application and thus from Realm and I'd like to test that it no longer exists.
When I set up my realm configuration I should be able to apply some objectTypes
, however the class is no longer in my application and I am unsure how to check for it.
Here's my current test set up where I am trying to test that my object exists in Realm v0. Note that this is my first migration with Realm and really my first experience with Realm.
let realmV0 = loadRealmFromResource(withName: "realm-v0")
// Test that MyEntity exists
// How can I specify my objectTypes without having access to MyEntity.self
// since it no longer exists in my project?
let configuration = Realm.Configuration(fileURL: realmV0, deleteRealmIfMigrationNeeded: true, objectTypes: objectTypes)
let realm = try! Realm(configuration: configuration)
let results = realm.dynamicObjects("MyEntity")
XCTAssert(results.count > 0)