Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get started with unit testing in Xcode 4?

Does anyone know how to get started with unit testing in Xcode 4?

How do I create a test and how do I run it?

EDIT: All the Apple documentation is for Xcode 3

like image 933
TheLearner Avatar asked Mar 22 '11 09:03

TheLearner


People also ask

How do I set unit tests in Xcode?

Create a unit test target by selecting the Include Tests checkbox when creating your Xcode project. Add unit test classes to the test target by choosing File > New > File. Import the XCTest framework in your unit test classes. Use the @testable import statement to give your unit test classes access to your app's code.

How do you write unit test cases in Swift 4?

Writing Unit Test Cases in Swift With an ExampleUnit test cases run with the testing target. Always check if you have a unit test target or not, if not, then add it. Then under this target, you need to create a new test case file. You will use this new file for writing test cases.

How do I get unit test coverage in Xcode?

Running Tests and Coverage Locally in Xcode To enable code coverage, click the scheme editor in the toolbar. Select the CodecovDemo scheme and choose Edit Scheme. Select the Test action on the left. Check the Code Coverage box to gather coverage data.


2 Answers

See this question: Unit testing in XCode 4

Basically, it says to use GHUnit and ignore SenTestingKit for now (bceause it's broken). GHUnit is pretty nifty.

like image 79
occulus Avatar answered Sep 22 '22 16:09

occulus


Although most of the documentation is in fact for XCode 3, the XCode4 User Guide: Building and Running Your Code gives clear step-by-step instructions. Essentially, you create a Cocoa [Touch] Unit Testing Bundle target and add all your test code to that target. Then add the target to your build scheme. Pretty straightforward (not something I'd say for XCode4 in general...)

I just switched from using GTM (which is what GHUnit uses) and it works fine. The main thing you get from GHUnit is the nifty UI which shows you all the tests and whether they succeeded. The other problems mentioned with OCUnit (such as no debugging) are no longer relevant.

like image 22
Ron Midthun Avatar answered Sep 21 '22 16:09

Ron Midthun