Skip to content
samkrishna edited this page Sep 18, 2014 · 17 revisions

Q: How do I use Kiwi with UIKit classes?

A: Xcode comes built in with support for 2 types of test targets, Logic Tests and Application Tests. The main difference between them is that an Application test target has a UIApplication instance and main run loop associated with it (OK, not entirely accurate but this is an easy way to think about it).

Most of UIKit requires the presence of a UIApplication to behave properly. Specs that perform operations on UIKit classes (e.g. UILabels) will probably crash weirdly if they are run under anything other than an Application Test. To learn more about how to set up an Application Test target, check out the official Apple docs.

Q: How do I test my private/internal methods?

A: This is less of a Kiwi question, and goes more towards testing methodology. Instead of testing internal methods that are specific to a particular class' implementation, we recommend evaluating the structure of the class to see if the functionality that needs to be tested can be extracted into a public class of its own. Testing internal methods is inherently brittle because internal implementation details are by nature the part of a class that changes the most. Your testing experience will be much more fun when it goes through a more stable public interface for the majority of classes. Discussion that brought about this question.

Q: Why does adding libKiwi.a result in a warning?

A: You may see the following warning when adding libKiwi.a to your project. ld: warning: directory not found for option '-L/Developer/Kiwi/build/Release-iphoneos'.

If you see this, make sure you are putting the Kiwi library somewhere where you have write permissions. If that does not help, create an issue. Discussion that brought about this question.

Q: Why Xcode shows error: Lexical or Preprocessor Issue: 'Kiwi.h' file not found


A: You may see the above error when building specs to run under Simulator, while test target has device base SDK. The error does not prevent tests from running, still is shown in red in Xcode. To fix the error build test target for device once, e.g. use build for testing while iOS Device is selected.

Q: How do I run my tests with continuous integration (such as Jenkins)?

A: The basic difficulty with this is that Xcode's command-line tool, xcodebuild, doesn't support running iOS tests from the command line. There are a few solutions, such as launching the simulator with WaxSim, but we've had the most luck editing copies of Xcode's testing shell scripts, as described by Stewart Gleadow and Manuel Binna.

Q: How do I run a single spec (describe/context/it)?

A: Kiwi supports running a single spec via setting the environment variable KW_SPEC. Set this to <file name>:<line number of spec> before executing the tests. For Xcode users, there is a plugin jerrymarino/CedarShortcuts, that enables a keyboard shortcut to execute the spec under the cursor.

Q: I'm having trouble running my specs with Xcode 6 and Kiwi (as installed by CocoaPods). I'm seeing a The bundle "MyAppTests.xctest" couldn't be loaded error. What should I do?

A: After upgrading your project to Xcode 6, you may be unable to load your test bundle. If you are using the latest released version of Kiwi (2.3 as of this writing), you are possibly seeing this error. Specifically tell your Podfile to use the head of the Kiwi repo like so:

platform :osx, '10.9'

target :MyAppTests, :exclusive => false do
    pod 'Kiwi', :head
end