Coming from Rails/Rspec, I'm used to being able to manage tests something like this:
setup { //stuff for all tests goes here }
tests for "foo" method
setup { stuff specific to foo method here }
test_foo_1 { ... }
test_foo_2 { ... }
end
tests for "bar" method
setup { // stuff specific to bar method here }
test_bar_1
end
So there's some setup run for all the tests in the file, and then for some tests there's additional setup that only applies to those tests.
I know about the setUp
and tearDown
methods; the thing I'm trying to do here is factor out setup code that applies to, say, 5 out of 20 tests for this file, but is unnecessary, or even harmful, for the other 15 tests.
Is an organization like that possible in OCUnit when building for iOS? The alternative I'm looking at now is defining some additional setup methods and calling them myself by hand from the appropriate tests.
Circling back on this, there are a couple of Objective-C testing frameworks which layer on top of OCUnit/XCTest and provide an rspec
-like test organization. Specta is one, Kiwi is another. Kiwi includes its own mocking and expectations support, whereas Specta has expectations factored out into a separate package called Expecta.
I'm using Kiwi for a couple of projects and it's working pretty well.