126

I am trying to run an Xcode unit test for my iOS application. I am willing to do it on an iPad connected via USB to a Mac. I am trying to run the test from the command line in order to trigger it from Jenkins later on.

Below is what I'm currently typing into the command line and the error I'm getting. Please help.

The code:

xcodebuild test -scheme MyApplication -destination "platform=iOS,name=iPad"

The error:

Scheme MyApplication is not currently configured for the test action

pkamb
  • 33,281
  • 23
  • 160
  • 191
danR
  • 1,518
  • 2
  • 11
  • 15
  • It seems not a jenkins related issue since you are not using jenkins yet. I suggest you to remove the jenkins tag. And search for similar questions here to see whether they help or not. http://stackoverflow.com/questions/20237064/unable-to-execute-tests-from-command-line-via-xcodebuild http://stackoverflow.com/questions/25970396/xctool-fails-to-clean-my-ios-project – mainframer May 27 '15 at 12:22
  • Thanks for the suggestion. I came across that example already. Looks like not directly related to my issue. In my case it is probably something to do with the schema sharing. I have a few schemes in my Xcode project, tried to share/unshare, delete and recreate them in different ways - still no luck.. – danR May 27 '15 at 12:33

12 Answers12

277

For me the problem was that no tests were added to my scheme:

Scheme Editor

By adding test bundles to my scheme via the '+' button then the scheme could be built by Xcode and xcodebuild.

David Hunt
  • 3,300
  • 2
  • 18
  • 11
46

For everyone struggling with this problem.

My solution was to:

  1. Select Test Target
  2. Manage Scheme
  3. Select Run in the left menu
  4. Select Info in the tab
  5. Choose Executable Target from the dropdown menu
  6. Hit Close.
Zonily Jame
  • 5,053
  • 3
  • 30
  • 56
dan
  • 873
  • 8
  • 11
  • This fixed it for us. I wonder if it has something to do with having Swift Package Manager libraries/frameworks included in your main app/target. Have not had to use this screen before (that I can recall) – race_carr Oct 20 '22 at 19:58
19

Please follow following steps to resolve this error.

  1. Select your project scheme at the top.
  2. Click on Manage Schemes.
  3. Select your test target in the popup.
  4. Make sure to click on Edit button at the bottom left of popup.
  5. Select Build.
  6. Click the checkbox below "Run"
  7. Close the popup.
Tarun Punhani
  • 191
  • 1
  • 2
18

Fixed this up by removing duplicate schemes from Xcode. The schemes can be added/removed/shared/edited in Xcode via Product -> Scheme -> Manage Schemes.

danR
  • 1,518
  • 2
  • 11
  • 15
  • 2
    Thanks! This was the clue I needed, and I'll mention a more subtle scenario that hit me: a second scheme, of the same name, but embedded in a dependent project. It seems this throws xcodebuild off, too, since it might favor the scheme inherited from a dependent project. – danielpunkass Jan 21 '16 at 13:57
  • 2
    To check for duplicate schemes run: `xcodebuild -workspace path/to/workspace/file -list` or `xcodebuild -project path/to/project/file -list`. Duplicate schemes can be leftovers from previous versions of the workspace, so a simple `git clean` may be all you need. – Ohad Schneider Dec 13 '16 at 18:36
3
  • You should check your workspace data on Jenkins and see which *.xctest is already uploaded. Then you have to rename your UI/Unit test target to that *.xctest data in your xcode project like what you have on Jenkins and then push again.
  • OR wipe out your workspace from Jenkins and push all data again with new UI/Unit test target again.

(Of course you have to ensure that you have already made a scheme for project.)

MiladTai
  • 31
  • 1
1

In my case I had no test file...

Here is a tutorial to perform UI Tests and create screenshots :

https://krausefx.com/blog/run-xcode-7-ui-tests-from-the-command-line

Charly
  • 436
  • 4
  • 12
1

In my case, it was failing intermittently with this error, turns out I had two schemes with the same name and Xcode sometimes picked the wrong one, so make sure you do xcodebuild -workspace "MyWorkspace.xcworkspace" -list to see all your schemes and find out if you have repeating names.

Moisés Olmedo
  • 919
  • 1
  • 17
  • 15
0

My problem was that the Tests.swift file was importing a module that no longer existed (I renamed the Targets for the project). Check to make sure all test files are importing currently existing modules.

KVISH
  • 12,923
  • 17
  • 86
  • 162
0

I was getting this similar error, but none of the other solutions helped. Since the error was first noticed while running via Fastlane, I next ran xcodebuild manually using this command to mimic the same.

xcodebuild -workspace Noname.xcworkspace -scheme Noname -enableCodeCoverage YES build-for-testing

I then saw errors regarding: Signing for "Noname-Dependency" requires a development team.

I also so reference to a macosx signing error, which I cannot sadly reproduce having since fixed the issue.

To fix the issue, under Signing & Capabilities for the Target I selected None and then under General I unchecked Mac, as we are not needing/using that but it was selected by default when creating this new project (CocoaPod).

Oddly enough, I added back Mac and things still kept working. I think that there is a oddity with the Xcode project file and/or scheme file(s) such that when you tinker enough with it -- things get reset/fixed.

Mark
  • 556
  • 8
  • 12
0

I had a test plan set up (xctestplan).

  1. I needed a separate configuration for the tests (the test plan) in addition to "Shared Settings".
  2. Please also make sure that the test plan (under Xcode scheme settings) includes a test target AND a configuration.

Screenshots attached:

Test Plan

Xcode Scheme test settings

inder_gt
  • 492
  • 1
  • 7
  • 9
-1

Your test plan should have at least one custom configuration.

Aleksey Tsyss
  • 136
  • 1
  • 5
-2
  1. Go to Manage Schemes.
  2. Delete all schemes and click on Autocreate Schemes.
Jin Lee
  • 3,194
  • 12
  • 46
  • 86
Ambesh Tiwari
  • 648
  • 7
  • 11