A first glimpse to testing in XCode6

In Mikamai all of our RoR applications are tested: sometimes we start from user stories, sometimes we just unit test some models and sometimes we practice TDD, but the general consensus is that if tests are present (and up to date) it’s better for everyone.

Keeping a sane test environment on an Objective-C (and lately swift) project has always been difficult, but fortunately it seems XCode 6 started supporting it.

So, how to start to unit test our code?

The testing framework we are going to use is XCTest
When we start a new project, XCode takes care for us of the creation of a separate target for our tests, it also creates a group where to include our test classes and it also provides us of an example test we can start looking at.

If we have created an example app creatively named Example, we’ll find an Example Tests target and a file named ExampleTests.m

Within it we already have some generated code: setUP and tearDown methods necessary to respectively set and clean up the environment for every single test we are going to describe in that testing class.
We then found a testExample and a performanceExample file: XCode allors us to perform a performance test and choose a baseline time to be used as a reference: if the performance test gets completed in a time greater than the baseline, a flag is raised as a result of the test.

Testing our XCode apps opens up to endless possibilities for their stability and maintenance and we’re going to share hints and tricks in the articles to come.

Leave a Reply

wpDiscuz