Xcode test cases shows no test coverage - ios

I'm having problem with getting code coverage in Xcode. It was working at some point of time, however after sometime it has just stopped showing coverage. I've checked both the schemes and test coverage plane for the appropriate settings.
This is how my scheme looks like:
This is what my test coverage plane shows after running test cases:

I tried many many things to get this fixed. Finally I ended up deleting all Xcode I had in the Mac, and cleared all the meta-data from /Users/bbirani/Library/Developer/. After all this clean-up, I re-installed Xcode and VOILAA!! it started working.

It happens to me a lot. Try restarting your xcode as well as the simulator(if you are using one). It seems like an xcode issue.

You can try some of this
Enabling the "show code coverage" from Editor while running a test case. I had this same problem before worked for me. Just try and see if that is working.
You can try checking the targets for the modules but not sure thats the case.
Or you can use the #testable way.This is a workaround and the long way to solve this.
Also u can try cleaning the whole project and deleting any derived data.And then try running the test case.
Also you can try deleting the scheme and try making a new scheme and check "Gather coverage data" for the same. If this things work then thats a xcode bug.
I hope your problem gets solved, I got stuck to the same problem before and it was frustrating to solve that, and you never know which way might work.

Maybe try using Slather instead?
https://cocoacasts.com/how-to-generate-code-coverage-reports-in-xcode-with-slather

Related

Xcode won't pause at this breakpoint because it has not been resolved

Shortly after updating to Xcode 13.2.1 I started seeing some weird behaviour of breakpoints. When I run an app (in a simulator) some of my breakpoints change their look and turn to dotted blue outlined. Xcode does not stop execution at these breakpoints although code has been compiled, loaded and executed. I checked it in Console by adding some prints.
When I hover over breakpoint Xcode shows a message:
Xcode won't pause at this breakpoint because it has not been resolved
Resolving it requires that:
The line at the breakpoint is compiled.
The compiler generates debug information that is not stripped out (check the Build Settings).
The library for the breakpoint is loaded.
All trivial solutions like reloading, reapplying breakpoints have not helped.
Did anybody else see something like this? Is there a way to solve it?
Screenshot for reference:
Ok, so in my particular case rebooting laptop has helped. All breakpoints are now good. But it would still be nice to know the cause of the problem.
Make sure that the file in which you are adding breakpoint is having correct target set in target membership.
Click on .m file in which you want to add breakpoint.
Select the file inspector.
Check if you have selected correct target for that file or not (check below image).
What worked for me, was to select the files, delete them with - Delete>Move To Trash - and then drag the files back from the trash to the project.
In my case the issue was happening, because class was not added to the target, which I was trying to build.
For my case somehow the code path was never invoked and very likely considered as dead code. The same thing applies when not adding the file to the target that you want to debug.
This can be the case or somehow debugger might not be able to resolve your breakpoint. The first thing in this case should be cleaning derived data and any caches.
But instead of recloning your repo you can just delete breakpoint config from the location described in this answer
In Xcode 14 the problem is much more prevalent and "consistent". I figured out one pattern where it always fails and how to mitigate it.
If you have a final class then breakpoints set on or inside a private method will have that issue. If you remove private from the method or final from the class the breakpoints will get resolved properly.
If tried everything and nothing worked I suggest the following:
Reclone your repo
This is what worked for me.
I just passed through this problem and the solution for me was recreating the files.
Note: The ones I was trying to originally breakpoint on were copied from another project. When I created the new files, even though their Identity and Type looked just the same (target membership, encoding, paths), for some reason breakpoints started to work again.
Note 2: When copying and pasting code to your new files (if done manually), migrated breakpoints - created in the older file - will continue to fail. Only the ones created in this new file will work properly.
Hope it helps.
My case
Working on framework development. Framework is injected into the sample app for development/run purpose. Breakpoints inside the framework won't work.
Fix
Just removing xcframework in sample app and replacing with framework.
Reason
xcframework are precompiled outside of the app, so lib isn't compiled when project is built and that's why breakpoints doesn't work.
For me reboot the Xcode, and it works~

Error when trying to run application after previously i deleted derived data Xcode 7.2

Hey I keep getting this error. I think its because earlier i deleted everything in derived data folder and now i get this error when i try to run my project this is a new little test project I'm doing for the apple watch does anybody know how to fix it? Thanks
I recognize this issue and I tried to restart Xcode, my computer, clear cache, clean etc when I also had this problem, without any luck. The only thing that got it working for me was to completely uninstall Xcode and remove all files. Check this post of how to do that.

Code coverage do not include code covered with UITests

In my simple app I have a few files that are tested by unit testing and uitesting.
I am pretty sure that in UITests I tested EVERY line in WLLoginViewController. The test passed, but it is not considered as 100% in code coverage for that file. Sometimes when I restart Xcode, run app again, clean app, hard clean app. Do some accidental things, it works. But run tests once again, and again it is not considered. Why? Any ideas how to fix it? Is it a bug?
As you already mentioned, sometimes Xcode says that you are testing 100% of your code and sometimes it doesn't. So it's really inconsistent. That is an indicator for a bug.
Since you are still using an Xcode-beta, it's most likely a bug in Xcode. I wouldn't worry to much since it's still a beta-version and would check later, when the final version is released.
Ok, I've found temporary workaround.
Remove derived data for your project (window->projects)
Quit Xcode and Simulator.
Launch Xcode with your project, and run tests.
Run tests again.
Remember to wait until indexing is finished:
Weird, but try and see:)

IDEBundleInjection.c: Error 3587 on Xcode 6.4

I am trying to start testing my app, and so I enabled a new test target and a Swift file for the testing. Yet when I try to execute the testing I receive error:
IDEBundleInjection.c: Error 3587 loading bundle '/Users/fbartolom/Library/Developer/Xcode/DerivedData/inArrivoHD-ebjdiuuwdpdvchgmpsyqkpvvvyhw/Build/Products/Debug-iphonesimulator/inArrivoHD Tests.xctest
By reading some threads I also recovered the XCTest.framework from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/ given it was not available in the selection, after locating it with find on the shell as Spotlight reported no results. Yet in so doing I got some missing symbols in the linking phase, so by reading How do I migrate from SenTestingKit/OCUnit to XCTest? I removed it.
I tried clearing the DerivedData folder several times to no avail. I also put code signing to "Don't Code signing" with changing anything.
What should I do?
I think I fixed the issue by followng the advice at:
http://dunghnt.blogspot.it/2014/12/problems-of-migrating-from-sen-test-to.html
The issue was due to incorrectly importing the MacOS test kit. Once I correctly chose the iOS one everything went in order. Perhaps a better error message would be appreciated.

xcode 5 can't see NSLog(s) from old iOS project

I have an older iOS6 app that I was playing with last year; it was only for my wife, so I never released it, but I wanted to dust it off and see if it was potentially useful to others. So I load it up in XCode5 (5.0.2 running on 10.8.4; I've also tried this on my home laptop running the same XCode and Mavericks). However, though the app builds and runs fine, none of my NSLog statements show up in the console, on either computer. I've cleaned, rebuilt, run it on every simulator and iPad I have, hunted through settings, torn my hair out, etc., but I can't figure out how to get them to show up. I started a new iOS app to make sure it's not something in my setup, but NSLogs from there work just fine. Unfortunately, I'm not even sure where to start looking to fix this. Does anyone have any ideas for directions that I should be exploring here? Thanks!
Edit: I just tried copying over the files into a new project, and now the NSLogs are showing up! Still leaves me with no ideas as to why they're not showing up in the old project.
Edit2: It's not just user error; I can see the log messages from the new project with the copied files (see image). They just don't show in the old project when I run it.
Maybe you're not opened a Console in XCode 5, it seems, you're trying see a logs in member console.
Try click at here and you will see console with "All Output" option:
As noted in the comment by #combinatorial, I had a debug statement hidden (so cleverly that I fooled myself) in the pch file. Thanks so much for helping me nail that down!

Resources