-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
-
3 - M (<= 1 month)
-
3725
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