OCHamcrest helping hand

Hamcrest: A Tool for Readable, Powerful Unit Tests

Shares

Unit test code is often tricky to read. Test output is often hard to read. There’s got to be a better way.

There is!

give me by sanja gjenero, used under Freeimages licence / Added text

Hamcrest is an important tool for writing unit tests. It’s now a standard feature of jUnit, and lets you build test expressions that are expressive and readable:

  • Readable source code
  • Readable diagnostic output

I’ve ported Hamcrest to two languages:

Since Quality Coding focuses on iOS development, I’ll write about OCHamcrest on this blog.

…But Justin Shacklette beat me to the punch! His post Intro to OCHamcrest is a nice overview. He introduces the many “matchers,”  illustrating them with code samples. He even makes special notes to call out areas that might trip you up.

I’ll eventually write about OCHamcrest myself. Until then, go check out Justin’s writeup.

Any questions about OCHamcrest? Leave a comment below.

See also: How OCHamcrest’s “hasProperty” Can Make Your Tests Simpler

About the Author Jon Reid

Programming was fun when I was a kid. But working in Silicon Valley, I saw poor code lead to fear, with real human costs. Looking for ways to make my life better, I learned about Design Patterns, Refactoring, and Test-Driven Development (TDD). Programming became fun again! I've now been doing TDD in Apple environments for 17 years. I'm committed to software crafting as a discipline, hoping we can all reach greater effectiveness and joy.

follow me on:
Disclosure: The links below are affiliate links. If you buy anything, I earn a commission, at no extra cost to you.

  • Harry Hacker says:

    OCHamcrest is really a valuable addition in unit testing code. However, I didn’t manage to get it working under iOS with automatic reference counting enabled.

    Is there a way to get OCHamcrest working in an ARC project under IOS? Or is it planned to include ARC support in the near future?

  • >