Compare these two files:
- https://github.com/sens3/records/blob/master/Records/RecordsTests/RecordViewControllerTests.m
- https://github.com/sens3/records/blob/master/Records/RecordsTests/RecordViewControllerSpec.m
and decide for yourself which one you like better.
Please run pod install before building the app.
- Folder RecordsTests holds the OCUnit tests.
- Folder RecordsSpecs holds the Specta specs.
- Scheme RecordsTests will only run the OCUnit tests.
- Scheme RecordsSpecs will only run the Specta specs.
Specta is a BDD Framework very similar to Cedar (by Pivotal) or Kiwi. All of these were heavily influenced by RSpec, a Ruby BDD framework.
If you leave the philosophical differences between TDD and BDD aside, the one huge benefit of using something like Specta is that it allows you to easily organize and group your tests (or "specs").
So, instead of having to keep all information in just the test method name
- (void)test_RecordListVC_viewDidLoad_setsTheTableViewDelegate
you can group your tests like
describe(@"RecordListViewController", ^{
before(^{
// stuff I need for all tests
});
describe(@"viewDidLoad", ^{
before(^{
// stuff I only need for this sub group of tests
});
it(@"sets the table view delegate", ^{
// assert things here
});
});
});
Which makes it much easier to navigate through your specs and identify what is being tested where.
Also, as you can see in the example above, you can have a before method (similar to setup in OCUnit) for each describe block (meaning for each group of tests).
This allows you do exactly the setup you need for an individual group of tests.
In OCUnit you could have either just put everything in the setup method (not always possible if you have competing values for a variable) or create a seperate TestCase for a group of tests.
Github: https://github.com/petejkim/specta
Expecta is a Matcher framework. If you look at the specs, Expecta is what allows you to write things like
expect(@foo).to.equal(@"bar")
instead of
STAssertEqualObjects(@foo, @"bar", nil);
There are alternatives, but this is written by the same guy who wrote Specta (who'd have guessed, right?) so I just rolled with it.
Github: https://github.com/petejkim/expecta
A Mocking framework alternative to OCMock.
Pros: nicer syntax
Cons: no partial mocks
Github: https://github.com/jonreid/OCMockito
I also added a few functional tests using KIF.
You can either run it from within XCode by using the RecordsIntegrationTests scheme.
Or you can use the runkif.sh script, it depends on ios-sim which can be installed via homebrew:
brew install ios-sim