Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-231

APIs for helping people unit test with Realm

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      As a follow-up to #3345:

      How should we expose APIs or other affordances to help people write correct unit tests that involve Realms?

      I talked with Thomas briefly about just exposing [RLMRealm resetRealmState] to public users. It turns out that this method is difficult to use correctly (i.e. in a way that won't cause tests to crash nondeterministically).

      We have some shared test code that we use for our own tests. Perhaps we could expose an XCTest-agnostic helper class that abstracts out whatever we need to do to make tests run correctly, and have users use that instead? Strawman example:

      class RealmUnitTestHelper {
          init(setupBlock: RealmTestBlock = nil, teardownBlock: RealmTestBlock = nil)
      
          // In-memory Realm is named automatically
          func runTest(testBlock: RealmTestBlock)
      
          func runTestWithRealmNamed(name: String, testBlock: RealmTestBlock)
      }
      
      // Usage:
      class MyTest : XCTestCase {
          let helper = RealmUnitTestHelper(setupBlock: { ... }, teardownBlock: { ... })
      
          func testFoo() {
              helper.runTest() { ... }
          }
      
          func testBar() {
              helper.runTest() { ... }
          }
      }
      

      Any other ideas are welcome.

      @bdash @tgoyne @jpsim @mrackwitz @kishikawakatsumi @stel

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: