Xcode UITest Record button is disabled - ios

Has anyone seen this happen before? I can not run UITests because the button is disabled. I have not found any help online. I have deleted and added a new test target, restarted Xcode and deleted derived data. None of these worked and I have no idea what to try next.

You have to create a new target in your project.
Steps:
1) File > New > Target
2) Select in left box: iOS > Test
3) In right box: iOS UI Testing Bundle
4) Run your aplication
5) Record your actions
6) Make assertions

Another possible cause could be that the UI testing target was not build/run successfully.
Go to Product > Test and make sure no errors. You should also see the test cases in the Test Navigator (if you don't see, then it is not recognised).

I had the same issue and finally found a solution.
Write a new UI test in a file which is linked to the UI test target.
In the new test write XCTFail("") (which will fail the test)
Run your UI tests and they should fail.
Remove XCTFail("") you added and the red button is now enabled.

For me it was Deleting ~/Library/Developer/Xcode/DerivedData/ as above, and letting Xcode reindex the project, but I had to make sure to not interrupt the index. Indexing took a while, and if its interrupted, it seems to not pick pack up where it left off. At least for XCUITest targets.

Try to delete
~/Library/Developer/Xcode/DerivedData/ and let xcode to reindex your project. This should do the trick

Make sure the name of the UI Test file is the same as its class.

I just fixed this by commenting out a failing test in my test class. Ran the test so it's green, and then put my cursor on a new line (below commented out test), and the Record button is red again.
You can have other failing tests in your app, but not in the file that is active in Xcode.
In Xcode 9.0

Click inside test function. You should select test method first. Usually when the button is not active, that means that xcode does not know which test to rec.

Related

My Test Navigator copies some test cases from one test class to another

In this case my method testDidSelectLocation() should be in DBLocationsViewControllerTests. For some reason this is copied into another classes, marked with violet icon, and trying to pass a whole test. That additional tests, sometimes do not pass the tests. It is fixed only when I mark it as disabled. How to remove them?
I got this problem after removing some of the tests which I don't need.
Following steps solved my problem:
1.)Quit Xcode
2.)Open your scheme file in a text editor(Don't use Xcode UI to edit scheme, you have to manually open from your local storage, I found it under: xxxxx.xcodeproj/xcshareddata/xcschemes/xxxx-tests.xcscheme)
3.)Delete all the skipped tests under <SkippedTests>...</SkippedTests>
4.)Delete Derived data folder under Developer/Xcode
5.)Restart Xcode

Adding test target to an existing project is not working

I need to add test cases to an existing project, so I tried adding a new test target via
File -> New -> Target -> Cocoa Touch Testing Bundle
From the test navigator filter bar.
Even after adding, the target is not getting listed in the test filter bar.
May be because of this issue, Product -> Test option is diabled in my project.
Also I could see some differnce between the build setting in my project and another sample project I started in Xcode 6.1 in which Product -> Test option is enabled and everything working fine for Test cases.
Please find the build settings screen shots.
Any help is appreciated.
I had this exact problem. It turns out my existing project was creating my Cocoa Touch Testing Bundle with the .app extension when it should've been a .xctest extension.
You can fix this by going to your test target you created. Build Settings > Wrapper Extension and changing it from app to xctest.
You may have to restart Xcode after this change to select your test target.
UPDATE: I found out the reason the Testing Bundle was becoming a .app extension in the first place. I had to go to the main project Wrapper Extension and make sure it was blank instead of .app. Apparently that was forcing all targets to become .app extension as well.

How to delete an Xcode Swift Test Class from the Test navigator?

The Xcode Test navigator shows a list of test case classes.
I want to delete a test case class because it's no longer needed.
I've tried many typical approaches, such as pressing delete, or looking for a "-" icon, or "Remove" menu item, or searching for help in Apple Xcode documentation.
I've found this workaround:
In the Project navigator, remove the file from the project and delete the file.
Quit Xcode and re-launch it. The Test navigator seems to lose track of the test classes and test cases, and show zero items.
Run the tests. The Test navigator seems to rebuild the list of test classes and test cases.
If that still doesn't work, try these...
Delete Xcode Derived Data:
Xcode menu -> Preferences -> "Locations" icon -> "Derived Data" section.
Click the tiny gray circle arrow; this opens the Finder and shows the DerviedData folder.
Delete the entire folder.
Rebuild:
Product menu -> Clean.
Product menu -> Build.
Is there a simpler way to accomplish the goal of deleting a test class? Ideally without needing to relaunch Xcode, or rebuild the project, etc.?
Related kind of issue: How can I delete Xcode test cases from the test case view?
I'm using Xcode 6.3 and Swift 1.2, if that helps to know.
Edit: In the comments, #CouchDeveloper points to the official Xcode 6.3 release notes, which describe a known bug # 20373533:
Swift tests are not automatically discovered in this release of Xcode. Test annotations in the source editor sidebar will not appear, and the test navigator and the table of tests in the Test action of the scheme sheet will be empty. ...
The bounty on this question is for any solution or better workaround. Any workaround is fine, such as using the Xcode GUI, or using command-line xcodebuild, or any shell script that kludges the project files.
If you want to delete just a single test class, you can click on the file name in the Project Navigator and press Delete and Move to Trash.
If you want to delete then entire Testing bundle, click your project name in the Project Navigator. Then select your Tests target. Click the minus (-) button at the bottom to delete it.
It is a good idea to do Unit Testing (and UI testing) in your projects. So if you want to add them back in then just click the plus (+) button.
See also
How to do a Unit Test in Xcode
Xcode UI Test example
Using Xcode 6.2, all I had to do was to switch to the Project navigator, select the file, and press delete. I then clicked the "Remove Reference" button in the confirmation dialog that appears. After that, the tests in that file disappeared from the Test navigator immediately. Adding the file back, the tests reappeared.
I didn't have any need to delete the derived data folder, restart Xcode, etc.
Adding the file to the project again instantly restored the tests in the Test navigator.
This is certainly the desired behavior, and it sounds like it's broken in Xcode 6.3 but possibly fixed again in 6.3.1. So the real answer may just be that you need to upgrade to 6.3.1 (or downgrade to 6.2).
Before:
After:
You can add and remove tests to the project easily using the class target membership checkbox. Find the class file in the Project Navigator and select it, then in the Utilities pane, click on the File Inspector and you will see a checkbox for target membership. You can toggle it on and off in there.

Xcode lost button test in xctest

I working on Xcode 6. When I coding XCTest, Xcode has been crash. When I reopen my Xcode, and it lost little diamond run button.
It should be:
But it got:
I open other project and it don't have this error. But when I create new target, it get same error (in other project).
I checked Target Membership, but it checked in target name. When I choose Test in Product>Test it run but the button not show.
Thank a lot, sorry for my bad english.
Prefix func name with test
Also try changing the targets
Click on the test file (unit test or UI test file)
Go to right panel and you'll see Target Membership.
Select the Unit Test target and all would be good to go.
There is two way to check it.
If you have multiple scheme, In top of Xcode, make sure you choose Test to run the test.
Click on your test class, then click right panel. In target membership, checklist the tests target.
In case you disabled indexing earlier,
Close all Xcode and Simulator instances
Delete this setting
defaults delete com.apple.dt.Xcode IDEIndexDisable
Restart Xcode
This should reenable indexing and should bring back the individual test button (diamond shaped) in the subsequent Xcode launch.
My issue was file was not included in the workspace. If not included, go to finder and drag and drop to that folder.
In Xcode 12.4 just Command+U or menu Product > Test and all buttons in your XCTestCase will appear again.
A possible answer for some - I had added a new scheme in Xcode, but the tests were only in the original scheme. Switching back to the original scheme re-instated my tests.
I just re-started my Xcode and it worked. as everything was set-up the way it should be !!
Prefix func name with test
example test function name:
secondExample() must be **testSecondExample()**
then clean the build file
use this shortcut key command + shift + k
Need More description?
But Try following troubleshooting...
check Target Membership of test file
Go to,
Xcode > Window > Projects
click on the delete button for derived data. Close Xcode and open again. You should be good to go.
Solution that is working for me in Xcode 13, SWIFT 5:
Open another Xcode file and then open the file wth your function again, the button should appear then.

How to remove target for unit tests in Xcode5?

I'v just upgraded to Xcode5, and my unit tests with OCUnit (SenTestingKit.framework) stopped to work. I'v tried various solutions but none of them helped, so I'v decided to remove the target for tests and add a new target "Cocoa Unit Testing Bundle" with XCTest. I know I could ask Xcode to convert existing one, but I would like to make a clean remove and add a fresh one. However, I can't find how to remove the target. Any ideas, where the button is hidden :) ?
Have you tried turning it off and on again? :)
Just right-click (command-click) the target:
Or select the target and hit the Delete (Del) key.

Resources