Unit test not running on IOS swift 5 - ios

I'm implementing unit test in Xcode 13 (13A233). I wrote simple test but my xcode fails running test on this project. On other projects it's running fine. It produces an error
Assertions: System: Test runner never began executing tests after launching. If you believe this error represents a bug, please attach the result bundle at /Users/apple/Library/Developer/Xcode/DerivedData/MunchON-eeidlzwuounsfvbrmieuosqzpsih/Logs/Test/Test-MunchON (Staging)-2021.10.05_11-35-54-+0500.xcresult
I'm unable to resolve this issue. Other questions that i have checked already:
http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/
Xcode 4.2, can't run unit test
OCUnit tests not running / not being found
OCUnit test cases not running

Try deleting DerivedData
Open Xcode > Preferences > Locations
Click on the arrow to open DerivedData folder
Delete all from DerivedData folder
Reopen Xcode project
P.S. DerivedData contains cached data such that indexed files etc
FYI It is safe

I had a similar problem and solved it by checking the "Allow testing Host Application APIs" option in the test target.

Related

Unable to build app for iOS, "unable to write module session file Session.modulevalidation No such file or directory"

yesterday I was working fine with Flutter, now i'm facing this issue and I already search everywhere for a solution but no success.
When I run:
flutter run
The build process starts and when its about to finish the error below is shown:
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Xcode build done. 12.3s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
error: unable to write module session file at '/Users/hencke/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation': fopen(/Users/hencke/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation, wb): No such file or directory (2)
note: Using new build system
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.
Exited (sigterm)
Looks like the process is trying to open this file Session.modulevalidation for writing, but this file really does not exist in that folder. And I don't know what to do.
Things that I already tried:
Reinstalling xcode
flutter clean
Clone my project again in another folder and try to build, but same error
Created a new flutter dummy project and tried to build, still same error
Rebooting machine several times
Give permissions to Staff to the DerivedData and ModuleCache.noindex folders
Deleted the DerivedData within hope that xcode build will recreate all the files needed, but, it created everything again but not that particular file.
So that's it, If any blessed human know how to 'recreate', or reset, clear some cache, I would be very thankful.
Before running your project, check everything is checked when running:
flutter doctor
and also make sure at least a device is connected or open iOS simulator first. You can check if flutter is successfully connected to the device by:
flutter devices
when you make sure that flutter detect your device or the simulator, then run your application by:
flutter run
After hours I finally found the solution as it follows:
Without any hope I opened my flutter project with Xcode, and then tried to build the Runner target from there, same error.
Then, I was browsing the Xcode preferences and something caught my attention, on Locations section I found something about DerivedData location, it was set as Default. So, I changed from Default to Custom location and I set to a new folder on my home directory:
Then immediately Xcode created the entire DerivedData/ModuleCache.noindex folder and with them, the Session.modulevalidation file as well.
Then I closed Xcode and tried flutter run again, and it was successfully build!
I'll let this answer to those who may come here for help.

Xcode unit test fail runnings immediately (without)

My project's unit test fails even before running!:
I've cleaned the build director, restarted simulator, tried on the device, disabled code signing, restarted Xcode...everything!
I cmd-u, cmd-ctrl-u, and it fails immediately.
I use CocoaPods, so run it in a workspace.
It works now, after restarting the computer!
Weird.

Xcode 9 - Could not attach to pid for Frameworks unit tests

I am getting the following error after migrating from one mac to another using time machine.
Could not attach to pid
Ensure "project title" is not already running,
and "system username" has permission to debug it.
The error occurs only when running the unit tests for (any) Framework project. Running an application on simulator and device works fine.
Running unit tests for an application works, but running it for any framework can't be launched due to this error. I am getting this error even with Alamofire or PromiseKit unit tests.
I tested the solutions suggested on similar questions on Stackoverflow (I deleted derived data, cleaned everything, reinstalled Xcode, restarted the mac ..) nothing solved the issue till now.
I am using Xcode 9.3 and tested this with Xcode 9.4-beta also.
I am running on Mac OS High Sierra - 10.13.4 (17E199)
Any help / suggestion is welcome!
After opening a bug report to Apple, they suggested me to:
Check if my user is an Admin user. It was the case.
Check if I have "_developer" group, in the output of groups command. it was the case. Use this command: dscacheutil -q group
Check developer mode rights using the command sudo /usr/sbin/DevToolsSecurity -status. The status was unknown for me.
Enable developer mode rights if needed, using the command sudo /usr/sbin/DevToolsSecurity -enable. This solved finally my issue!
If you have Mojave OS then:
1) Open your target scheme
2) Uncheck this one
3) Select this scheme while testing this target (ex. Testing "TestApiTarget" - select "TestApiTarget" in schemes on tests).
Its temporary solution from bug report
I was able to resolve this issue by:
adding Single View App target (I named it HostApp)
setting HostApp target as a host application for test target
You can try some following steps -
Open the keyChain and check the Keychain certificates and delete the existing ones which are expired.
Uncheck the - automatically manage sign in from Xcode project settings.
Delete any derived data
Clean the project by cmd+k
Then Close and Restart the project and Run...
I hope it will work.
You can do this following steps -
Kill your simulator and then run it again from Xcode.
If you are trying to build too fast after a build has started. Try
stopping and running the project again.
This can be a issue with the untrusted certificates in key-chain access, please remove such a type of certificates and re-build again.
Finally, you can do is recheck the Keychain certificates. Delete the exiting ones by right clicking (they'd passed expiration)
and unchecked "automatically manage signing" in Targets->General
Hope above steps will solve your problem.
Haven't seen this exact error, but I've found removing the derived data helps fix some transient errors that pop up after updates etc.
You can find the location of your derived data folder in Xcode.
Open preferences/locations and click the arrow.
Once in derived data you can remove all the folders.
FYI after deleting the derived data folder all your projects will need to be rebuilt.
Hope this helps!

Xcode 9 Beta Build System fails with no errors

So, this is strange. Trying to build my fairly large project with the new Xcode Beta Build System and it fails with 0 errors. The old build system works fine.
The status bar at the top of the IDE displays the following:
Planning build...
Scanning build tasks...
It has got further than this before, but now seems to be failing really quickly. No idea how I can debug this. Any ideas?
I would recommend you to try these steps:
Quit Xcode
Delete folder ~/Library/Developer/Xcode/DerivedData
Reopen Xcode and try again
Hope it helps
EDIT: Quiting and reopening of Xcode after deletion of derived data is essential, because Xcode can hold derived data in it's cache. So deletion of derived data when Xcode is running does not help very often.
Remove 'Derived Data' before running the build.
To remove, go to
File > Work Space Settings > Go to the directory path > Delete.
Do not forget to clean the project
Cmd + Shift+ k

Xcode 5: Multiple test targets in one scheme: "Simulator already in use"

In Xcode 5, I have a workspace with multiple projects and a scheme that should run all the test targets of the various projects. When I kick off the tests about 3 test project targets pass. So far, so good. But at the fourth test target I get an error message from Xcode telling me that the simulator can't be launched because it is already in use.
Is there any way to kill the simulator between each test target(!) in a single(!) scheme?
Or are there other solutions?
Edit: I have opened a rdar for this: http://openradar.appspot.com/15153136
Thanks!
I have come into this error whenever i try to run my functional tests using calabash. One way to do this maybe be to run a script in the after each build process to kill the simulator.
this guy has wrote a bash script that does this
http://cdrussell.blogspot.co.uk/2012/04/script-to-kill-iphone-simulator-if.html
Might be worth running this as a build phase for each test target

Resources