title: Testing for equality in Realm
body: <p>I'm trying to test for equality among <code>Realm</code> objects in unit tests.  However, I'm unable to get objects to return <code>true</code> for their equality.</p>
  
  <p>According to the <a href="https://realm.io/docs/swift/1.0.2/#injecting-realm-instances" rel="noreferrer">Realm docs here</a>, I should be able to do that:</p>
  
  <pre><code>let expectedUser = User()
  expectedUser.email = "help@realm.io"
  XCTAssertEqual(testRealm.objects(User.self).first!,
                 expectedUser,
                 "User was not properly updated from server.")
  </code></pre>
  
  <p>However, I get the following test failure with the following code:</p>
  
  <p><strong>Realm Model</strong></p>
  
  <pre><code>class Blurb: Object {
      dynamic var text = ""
  }
  </code></pre>
  
  <p><strong>Test</strong></p>
  
  <pre><code>func testRealmEquality() {
      let a = Blurb()
      a.text = "asdf"
      let b = Blurb()
      b.text = "asdf"
      XCTAssertEqual(a, b)
  }
  </code></pre>
  
  <blockquote>
    <p>XCTAssertEqual failed: ("Optional(Blurb {<br>
        text = asdf;<br>
    })") is not equal to ("Optional(Blurb {<br>
        text = asdf;<br>
    })")    </p>
  </blockquote>