Xcode lost button test in xctest - ios

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.

Related

With XCode 8.x how do you clone an existing target?

With XCode 6.4 I could easily clone an existing target. However this functionality doesn't seem to be available in XCode 8.x.
Does anyone know how to do it?
Select your target, right-click on it, then select Duplicate.
As you can see - the project now has 2 targets:
I could not figure out what I was missing. The above answer is missing a step. The panel where you can duplicate targets is probably hidden.
Click the side panel button to see the targets.
Now you can see the targets and right click to duplicate, then just click on the name and rename it. Much easier.

Xcode UITest Record button is disabled

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.

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.

I need to run XCode 4.3 project twice in order to launch the cocos2d application

it drives me crazy, that my cocos2d project runs every second time on the device.
Every other time it says "Finished running " without launching the application.
My os version is 10.7.3 and I run xCode 4.3.
Other projects seems to work fine.
Any ideas?
BR,
Marcin
There were two Info.plist files under Resources folder. One of them was also under Copy bundle Resources tab in Build Phases section of the target.
I don't know how this happen, however I deleted one of the plist files, then removed it from the Copy Bundle Resources tab and now the project runs every time.
I found the second file while I was inspecting the whole project file by file. XCode does not report, that something goes wrong. I simply saw two files with the same name in Project Navigator pane.
Okay, I found a way to automatically do this.
Click the project icon, go to target, go to Build Phases tab, and at the bottom you should find the Validate Settings button. Click it. A window will show with an option to clean the "multiple references" of a resource. Use that, and XCode will do the rest.

Resources