Moving discussion over to mobile-l. Clever subject.

On Wed, Apr 8, 2015 at 6:54 PM, Brian Gerstle wrote:
I didn't mean to suggest you can't mix and match.  The author of that article endorses Specta/Expecta and OCMockito, but AFAIK Expecta matchers still aren't natively supported in OCMockito.  Whereas OCHamcrest can be used inside OCMockito expressions.

On Wed, Apr 8, 2015 at 9:45 PM, Corey Floyd <> wrote:
Looks like Expecta / Specta are able to work with OCMockito pretty well actually, so that shouldn’t be a concern:

There are even some nice Xcode templates with OCMockito/Specta/Expecta:

Even though we haven’t written any Swift yet, we should look into those new libraries as well for completeness. 

On Wed, Apr 8, 2015 at 9:07 PM, Brian Gerstle wrote:
The other two new kids on the block are Quick (BDD specs, similar to Specta) and Nimble (expectations). The main advantage of these two are Swift & ObjC compatibility (future-proof).

Here's how I see w.r.t. matching frameworks, since IMO BDD stuff is orthogonal:
  • OCHamcrest
    • pros
      • it integrates *really* nicely w/ OCMockito (same author)
        • we could try to write adapters for Nimble/Expecta matchers, but IMO it's tedious
        • also assumes we're using OCMockito too (mocking isn't really possible in Swift yet due to the lack of a reflection API)
      • assertion failures are nicer than XCTest
    • cons
      • API is macro-heavy and clunky, but gets teh job done
  • Expecta
    • pros:
      • really nice API, even has crazy "objectification" so you don't need to box primitives (i.e. expect(YES).to(beTrue()) just works)
      • has async matchers
    • cons:
      • not compatible w/ any mocking frameworks AFAIK
  • Nimble
    • pros:
      • really nice API, similar to Expecta
      • also has async matchers
      • built with Swift in mind, but maps really well to ObjC
    • cons
      • minor, but doesn't have auto-boxing of primitives like Expecta does, but that's not necessary in swift anyway
      • uses bleeding-edge swift language features, so you need Xcode 6.3 beta to run it
For now, Id vote for sticking w/ OCHamcrest given that we're using OCMockito.  There's also OCMock, which I have experience with, which also accepts OCHamcrest matchers.

That being said, we can always use Nimble in Swift tests :-)

On Wed, Apr 8, 2015 at 8:59 PM, Corey Floyd wrote:
Hey guys keep forgetting to write this… We added OCHamcrest before we really started formally evaluating 3rd party libs. So wanted to open the discussion now, especially since we have been writing tests in earnest. Also I hadn’t used OCHamcrest before, so wanted to try it out for a bit before discussing.

After looking around it looks like Expecta ( is the other big matcher framework. These 2 articles compare Expecta and OCHamcrest:

Personally, I find the Expecta matchers much more readable to OCHamcrest. 

This is confirmed when I read our OCHamcrest code. I notice that my eyes have to bounce around a bit to actually understand what is happening. The expectation is nested at the end and sometimes you jam in a description in the middle which makes me stop and look at it for a bit. This is an example in our code:

 assertThat(@([self.controller.fetchedIndices containsIndexesInRange:attemptedBatch]),
               describedAs(@"batch range to be optimistically marked as 'fetched'",
                           isTrue(), nil));

I don’t know if we need to say we can only write tests using one framework or another, but we should probably discus it as a group and then formalize it into a best practice.

Related to this conversation is Specta ( which can be used with either Expecta or OCHamcrest but adds some BDD syntax.