Sporadic results in XCTest #1350
Comments
How is it failing? Is the object not being found, or is there stale data from previous tests resulting in the asserts failing? |
Ah, I should have specified -- it always fails with the object being nil. |
Are there any uses of in-memory realms or other places where |
No in memory realms. I only set the default realm to the test one, in Note - when I print out the defaultRealm's path from the TestUser class (where I'm creating the record), it's properly set to my test realm path. |
I just tried doing the same without using the defaultRealm, but instead passing through the test realm to the createUser method, with the same sporadic result. |
Are any of your tests doing thing on multiple threads? If there's a background thing using Realm that sometimes finishes and is deallocated after |
Nope, everything is on a single thread. Also, the above test example will fail even when run alone. |
Hi @bredfield, I'm sorry this is causing you some problems. It doesn't look like you're doing anything wrong from what you've told us. We'll need access to an Xcode project where we can reproduce this issue to troubleshoot further. Do you think you could send us anything? You can email us code privately at help@realm.io if you prefer. |
Hey @jpsim, thanks for looking into this. It's quite possible it is on my end. I've set up an example project that's exhibiting the symptoms: https://github.com/bredfield/RealmTest. |
The problem is the |
Great find! Have you run into any similar dynamic casting issues previously? Is there a preferred way to cast to the object's class? Note: Another Note: A forced downcast does cause a
|
+1 |
1 similar comment
+1 |
Do we have any idea if this has been solved, or is being looked at? |
Hi all, thanks for your patience on this. The problem demonstrated in the example project created by @bredfield was caused by compiling an RLMObject subclass in both the app and test targets. tl;dr; don't add your app's Swift files to your unit test targets. Please read bredfield/RealmTest#1 for a more detailed explanation of what was happening and how it can be fixed. |
Using Xcode 6.1.1, Swift, and Realm 0.88, I'm getting some weird results with testing RLMObjects.
When testing the success of a model's creation, tests will (in a seemingly random fashion) pass or fail. I'm assuming this relates to the race conditions, as described here: https://groups.google.com/d/msg/realm-cocoa/LZQou7g8or8/lSmoy5beTRIJ.
I'm using the SwiftTestCase as a base test class: https://groups.google.com/d/msg/realm-cocoa/LZQou7g8or8/lSmoy5beTRIJ. With one addition: since my models always use the
defaultRealmPath
, I set the path to the test path insetUp
:When testing a model function that creates a user, something along the lines of this:
With a simple test such as:
The test will sporadically pass or fail.
Is there something else I should be doing to alleviate the issue?
The text was updated successfully, but these errors were encountered: