How to add helper methods to XCTestCase unit in Xcode?

ios, objective-c, xcode, xctest

Solution

Only methods that start with `test` will be considered tests. So, just name your helper method something that doesn't start with `test`.

By the way, I would not be inclined to put `XCTAssert` statements in your helper method. It works (the appropriate tests will fail), but in some scenarios it makes it hard to decipher which tests caused the assert in the helper method to fire.

Problem

Is there a way to add a method to your XCTestCase without it being counted as a test? Something like `setUp` and `tearDown` which exists already. One usecase would be to do a certain operation on an object in some of my test cases at specific points in time, while accessing the instance variables of the class itself (which rolls out the possibility of using static methods and external helper files)

Original source