Tips & Tricks

Unit testing with AppCode

Today we’ll talk about unit testing support in AppCode. We’ll assume that you already know how it works in Xcode, and that you’ve read our previous post about run configurations. Let’s focus more on the details of how it’s done in AppCode.

First, if you already have an Xcode project with configured unit tests in it, and you open it in AppCode, you need to create test run configurations: go to Run | Edit Configurations and add a OCUnit configuration.

Here you need to specify a class and methods to be run – note, that you can use code completion in these fields. If you leave the Class field blank, all tests in the target will be run. The rest of the options are similar to regular run configurations.

Now, when you want to run your tests, you can do it the same way you run your app – choose a configuration in the right upper corner of the IDE and click the green arrow button, or select it from the Run popup (Ctrl+Alt+R) invoked right from the editor.

When you run your tests, a dedicated tool window will appear at the bottom of the IDE showing you the progress and the results when ready.

Let’s take a moment to inspect the options that this tool window provides.
On the left vertical panel there are the two important options: rerun current configuration and stop.

You can find a number of options above the tests tree that can help you investigate the problems faster: hide successful tests, sort them alphabetically, navigate to previous/next failed test (which can also be done with shortcuts Alt+Cmd+Up/Alt+Cmd+Down) and export test results.

To find a test in the tree by name you can use speed search like in many other views – just start typing its name.

Under a gear-like icon you’ll find a number of settings allowing you to control the presentation of the tests in the view and enabling additional features e.g. statistics.

From this tool window you can easily navigate to the failing test code – simply click on the test in the tree. When you have fixed it, you don’t need to re-run the whole bunch of tests, you can re-run only this test in question: select the test and hit Ctrl+Shift+R (or choose it from the context menu).

You can also run a single test from the editor. Position the caret anywhere inside a test method and press Ctrl+Shift+R (Run [test name] from the context menu)to run this particular test. AppCode will create a temporary test run configuration which you can save and reuse later. You can also position the caret within a test class (but outside of the methods) and press Ctrl+Shift+R to run all tests in the class.

Now, in addition to all above, here’s a short FAQ.
If my project doesn’t have unit tests yet, how can I add them?
Currently you need Xcode to do that – can add Cocoa Unit Testing Bundle or Cocoa Touch Unit Testing Bundle target in Xcode. In AppCode you can add individual tests by generating them from Xcode template: in Project view hit Cmd+N and choose File from Xcode template.

Can I run tests on device?
Yes, you can – change the destination for test run configuration the same way as you do with normal run configurations.

Can I debug tests?
Yes, you can. Use Ctrl+Alt+D shortcut to debug instead of Ctrl+Alt+R.

How to run Kiwi tests?
The same way as OCUnit tests – configure Kiwi tests in Xcode, and create a test run configuration. You only need to remember to open *.xcworkspace project file not *.xcodeproj if you have added Kiwi tests via CocoaPods.

That’s about it!

Comments below can no longer be edited.

30 Responses to Unit testing with AppCode

  1. Avatar

    David Linsin says:

    June 27, 2013

    You should also mention that you can navigate to a Test class by hitting Navigate -> Test Subject.

  2. Avatar

    Maria Khalusova says:

    June 28, 2013

    true, thanks!

  3. Avatar

    William Zhao says:

    July 10, 2013

    very good!

  4. Avatar

    Pritesh Shah says:

    August 6, 2013

    I have an Xcode 5 project with a unit-testing target. As mentioned above, I went to Run | Edit Configurations and tried adding a OCUnit configuration. But, I see “No variants” in both the Target and Configuration drop downs (and they are disabled).

    Can you please help?

    • Avatar

      Pritesh Shah says:

      August 6, 2013

      Nevermind, I found an open bug for this issue.


      • Avatar

        Andrew Velis says:

        August 17, 2013

        @Pritesh Shash Could you possibly link that open bug. Your comment is pretty recent I am curious to track it.

        • Avatar

          Anton Makeev says:

          August 21, 2013

          Andrew, here is the bug report. The problem is that AppCode 2.1 doesn’t support XCTest framework, but we are preparing AppCode 2.5 EAP that will be open in a week or two, and it will have full support of XCTest.

          • Avatar

            Jason Hanson says:

            August 28, 2013

            Thank you for working on AppCode 2.5 EAP. I am eager to run my tests in AppCode again!

  5. Avatar

    Sean says:

    February 20, 2014

    Note to anyone who had issues with proper syntax highlighting in kiwi:
    Make sure to pod install once you install kiwi. Effectively, you are doing a pod install twice.

  6. Avatar

    Lex Chou says:

    August 12, 2014

    I’m using AppCode 3.0.4 and following the tutorial from to make a Google Test case on a Makefile project(generated by cmake),

    But stucked at creating a command line target, it prompts:

    Cannot create target: Not a directory

    What should I do now?

    • Avatar

      Alexey Utkin says:

      August 13, 2014

      With AppCode 3.0.4 at 20th sec you cannot follow the video.
      Accelerator cmd+N does not work.
      You need to click the ‘+’ in the “Project Setting” dialog (frame
      It is in left-bottom corner of the dialog tab.

      • Avatar

        Lex Chou says:

        August 13, 2014

        Actually that’s what I did.

        It prompts that error when I click “Finish” button in “Create New Target” dialog.

        • Avatar

          Alexey Utkin says:

          August 14, 2014

          OK. Did you choose OS X | Application + Command Line Tool options?
          If yes, you may be have permission problem in project folder.

          • Avatar

            Lex Chou says:

            August 14, 2014

            Yes I did choose OSX | Application + Command Line Tool option, I did exactly the same steps in the video tutorial.
            It’s not a permission issue, I confirmed by “chmod -R 777 project-folder” and tried again.
            is there any internal log I can provide for you?

          • Avatar

            Lex Chou says:

            August 23, 2014

            Another question.
            If I create a “Google Test” configuration in “Run/Debug Configurations” dialog, my external build system target will not be listed in the “Target” field, but the “Command Line Application” target is listed.

  7. Avatar

    Bryan says:

    September 3, 2014

    I have a configuration called GoMachineSDK in XCode 5.1.1 that works without any issues. I run the Test (Product->Test) and have problems running all the XCTests.

    In AppCode 3.0.4, I create a XCTest/Kiwi configuration as detailed. I call it All Tests, level Class: empty (to run all tests). Set the target to ‘GoMachineSDK Test’ (its the only one in the list), and set Configuration to Debug (also tried Release).

    When I run the target, I get ‘No tests were found’ in the Run window as well as:

    /Users/bryan/Library/Caches/appCode30/DerivedData/GoMachineSDK-cab1572a/Build/Products/Release-iphonesimulator/GoMachineSDK.framework -XCTest All
    Testing started at 11:19 AM ...
    Simulator session failed with error: iOS Simulator failed to install the application.

    Process finished with exit code 1
    Empty test suite.

    • Avatar

      Vyacheslav Karpukhin says:

      September 4, 2014

      Bryan, please try opening your test target in Xcode, going to the General tab, and changing “target” value from Custom to None.

      • Avatar

        Bryan says:

        September 5, 2014

        Thanks, that got me a bit further. Now I am getting a ton of linker errors. These are all classes in the dependant target. Even tried linking explicitly to the generated framework in the build phase — no love though.

        Unfortunately I am under a deadline right now and do not have time to debug AppCode. As I said, I am able to run the tests with no problem in XCode. Its a bummer cause XCode is absolutely the worst IDE ever made, especially for debugging, probably even worse that Eclipse.

        Error:Undefined symbol ‘_GOFMimeTypeJPEGImage’ referenced from:
        Error: ___30-[GoMachineSDKTests testBasic]_block_invoke_2 in GoMachineSDKTests.o
        Error: ___30-[GoMachineSDKTests testBasic]_block_invoke624 in GoMachineSDKTests.o
        Error: -[GoMachineSDKTests addChatMessages:count:] in GoMachineSDKTests.o
        Error:Undefined symbol ‘_OBJC_CLASS_$_GOFAccount’ referenced from:
        Error: objc-class-ref in GoMachineSDKAccountTest.o
        Error:Undefined symbol ‘_OBJC_CLASS_$_GOFChangesCommand’ referenced from:
        Error: objc-class-ref in GoMachineSDKTests.o
        Error: objc-class-ref in GoMachineSDKSyncTest.o
        Error:Undefined symbol ‘_OBJC_CLASS_$_GOFChannel’ referenced from:
        Error: objc-class-ref in GoMachineSDKTests.o

        • Avatar

          Ryan says:

          August 28, 2016

          Bryan, recently I also encountered the same issue. The way I solved it is that open Xcode-> click the project name in the right side bar->click the test class under”Targets”->choose the host application(ur project) and tick the “allow testing host application apis”.
          Then go back the Appcode, the test method can build now.

  8. Avatar

    tommys says:

    September 5, 2014

    In IntelliJ there is a short key command for creating a corresponding unit test for a selected/appointed method(obviously not the test in its whole but its definition)
    I cannot find such a feature in appcode – is it not available yet?

    I believe that the default shortcut in intelliJ for creating a corresponding test method is is ctrl+shift+t (and also navigate to it, if already created)

    • Avatar

      Vyacheslav Karpukhin says:

      September 5, 2014

      No, unfortunately this is not available yet.

      • Avatar

        tommys says:

        September 5, 2014

        in intelliJ os also a magnificent feature that highlights the code that has been executed by tests – I suppose that is on the backlog aswell :/

        (is there any way to contribute to the development of these awesome features?)

  9. Avatar

    Mitch says:

    April 7, 2015

    How do I ignore specific tests? For example, I have a set of tests that don’t need to run every time, but I have 100+ tests that do. How do I ignore 1 and include all the others?

  10. Avatar

    Hari says:

    April 24, 2015

    How do create a suites each suite with couple of test cases and run as a single master suite through XCTest?

    • Anastasia Kazakova

      Anastasia Kazakova says:

      April 27, 2015

      You can create a couple of suite (classes) and list several via ‘,’ in the configuration.

  11. Avatar

    Anton says:

    April 18, 2018

    Unit testing in AppCode produces error

    > LLVM Profile Error: Failed to write file “default.profraw”: Permission denied

    Otherwise it works, but the error is rather annoying. Is it possible to fix it?

    • Stanislav Dombrovsky

      Stanislav Dombrovsky says:

      April 18, 2018

      Looks like it’s from Xcode so we cannot fix it.

  12. Avatar

    Pawel says:

    June 20, 2019

    Does AppCode supports test coverage?

    • Stanislav Dombrovsky

      Stanislav Dombrovsky says:

      June 26, 2019

      Not yet. We plan to add it in 2019.2 EAP.

Discover more