Adding Logic Tests to the project in Xcode 4.5 - iphone

I'm using xcode 4.5 and trying to add logic tests to the project. (This is actually a test, newly created project without unit tests). I'm following this guide:
http://developer.apple.com/library/mac/#documentation/developertools/Conceptual/UnitTesting/02-Setting_Up_Unit_Tests_in_a_Project/setting_up.html
So, what i've done so far:
Created a new project (View Based Application template)
Click on File -> New- CocoaTouchUnitTestBundle
That's it. The tests (as documentation states) are ready to use.
But I have the following problems:
The SenTestinKit.framework appears in red
If I press Test button issue navigator shows nothing:
If I select another debugger here(LLDB by default, trying to select GDB):
Xcode just hangs out:
P.S I also tried to remove SenTestingKit.framework (which is in red) and add new. Nothing changed.
What am I doing wrong ?? I suppose to see something like this(screenshot from apple guide):
Any help will be greatly appriciated!

Actually, your code works now.
I don't know why Xcode didn't initially add the SenTestingKit framework in correctly when you created the test bundle.
But now the code, "testExample" which was auto-generated for you, is running, and it is telling you to add in some real tests, by giving you an error. That's what STFail does.
So, if you take out that line, and start writing your own tests, you should be fine.

Related

getting module not found after importing packages in swift

I've done a bit of swift, but I've never tried to use a third party package before. I created a brand new swift app, with Mac/iOS version and tests from the wizard. I went to xcode, right clicked on the sidebar, and chose add packages, and put in a package by url:
https://github.com/witekbobrowski/EPUBKit.git
It goes away for a little bit - and three package dependencies appear on my screen:
and when I look at my project settings, I can see them there:
(I actually added the zip package separately after the first one didn't work, just to test it, wondering whether something was wrong with the package)
Anyway - I can now see the packages, browse into them, see code or whatever - and the package found its own dependencies, so everything looks like it's working fine. But if I go into my swift app main, and add
import EPUBKit
or
import Zip
it just says "No such module ...".
I've obviously missed a step - what am I doing wrong - how do I fix it? I don't even know how to investigate it, because everything I look at just looks completely fine and I don't get any errors. I tried cleaning builds, restarting Xcode, using the real version of Xcode 13.2.1, using Xcode 13.3 beta - and nothing works.
NEW LEARNINGS
so - I tried changing how I'm running it to produce an IOS app - and it's working fine - but when I produce a Mac app, it's like the package isn't even there? Why would that be, and how do I make it work for Mac as well as IOS?
Author of EPUBKit here, thanks for taking interest in my library!
The issue is reproducible in a new project which kinda makes sense but don't at the same time. I am glad Xcode is not adding a package to every single target in my project but at the same time why does it assume that I want it in the iOS target? Anyway, I know that this question was already answered in the comment and the problem is solved but I might as well just drop more detailed instructions. Maybe it will help someone.
1. Select Project from Project Navigator
Select te target that is not working for you, in this case it's the macOS target. In the General tab you will see the Frameworks, Libraries, and Embedded Content section. If the package is missing from the list, tap the plus button at the bottom.
2. Add Missing Library
Look for the one you are missing, in this case its of course EPUBKit and tap the Add button.
3. Success
Now the library is successfully added to your target. Go ahead and build the project to run and enjoy your app :)

Xcode doesn't pick up files changed by pre-action script

In my project I need to generate a file that will be used in one of my Swift Packages.
I added a script to generate it as a pre-action to make sure it happens before anything else is build - and it works.
File is generated properly - it appears in Xcode project itself.
But Xcode doesn't pick it up when compiling this Package for the first time.
Next time I compile it - it catches it properly, but all further changes are not picked up again on first time it gets modified...
I found this thread with similar issue, but none of the solution works for me.
Doing it as a Step in Build Phases doesn't solve the problem, making it even worse.
Is there any reasonable solution to run some code generate that will be properly picked up by Xcode ?

Xcode does not recognize new test functions

I've just started writing unit tests and I've encountered an issue. So far I've dug through different blogs on google and stackoverflow but I haven't been able to resolve this.
Every time I write a function to be tested the run button (shaped like a diamond) does not appear. The only run buttons that do show up are the default functions created by Xcode when you create a new unit test target.
Here's an example of the issues.
Xcode screenshot
Could it be a bug or am I missing something?
test needs to be on the front of the function signature. ie: test"functionName"()

I am having trouble with TDD with Swift

I am trying to write a test for a new function that I want to add. However, when I run the test the project won't build for a completely unrelated reason. A normal build works fine. As you can see below, the errors are stating that the struct WeatherDataOutput is not declared. It is declared. The test class is empty. I'm not sure why I'm getting this error in Xcode. I restarted Xcode and I cleaned the project, but nothing is working for me. I would appreciate any help on this.
Thanks
After you've cleaned everything, then perform build for testing, sometimes the build succeeds and an error still shows in the source code interface which shouldn't be there. It's a bug in Xcode.
When this happens: put your cursor at the end of the offending line and hit enter, then delete (add a new line then remove it).
I've had to do this countless times in my own projects. Really, just modifying the offending line slightly then changing it back is the idea. New lines at the beginning or end of the offending line seems to be most effective in my experience.
OR
Remove the AppDataStorage source file from your test target.
If you want AppDataStorage in a separate file in your test suite, add the import WeatherDemoApp to that file. If the file also contains a test case class, use #testable import WeatherDemoApp

How can I debug in a framework in Xcode?

I have two projects, one is the networkLib for login and some other network function, the other is the usingLibDemo. So I have all the source code of both projects.
The networkLib project outputs a framework, called myNetKit.framework, which is used by usingLibDemo.
Now I successfully use myNetKit.framework to login, but sometimes it crashes, maybe in main() without stack information, but sometimes Xcode gives me the stack info like below:
So I know where it crashes:
But the Utils.m is not exposed, how Xcode gets the stack info and the crash line, and eventually open the source file for me? Because that I have the source code in my disk?
If so, how can I debug the myNetKit.framework step by step, when it is not crashed?
Thanks a lot for any tips.
If someone would have the same question in future (now I am using Xcode 8):
You can:
build your framework project (in this example "networkLib")
copy project output ("myNetKit.framework") to destination project ("usingLibDemo")
run destination project ("usingLibDemo") on your device
stop process
launch app from your device manually ("usingLibDemo")
open framework project and Attach to Process of your app (launched in step 5). In Xcode 8: Debug->Attach to Process-> Select name of your app.
Don't forget set some breakpoints in your framework project.
When the library is built with all symbols, it contains full paths to the each source file embedded in itself. You can actually see this if you open the .a with a hex viewer. With this in place, the XCode will know how to get to the source file.
Setting breakpoints is somewhat more challenging. You basically have to make XCode slowly discover source files from your library by stepping into methods in those file. Once XCode has opened the file, you can set the breakpoint anywhere in it.
It is a bit painful but it works and you do not have to make the library project a subproject if you do not want to.
The following works considering the scenario that you have the framework project separately and added a.framework to some project B.
Go to your project B, add a breakpoint anywhere.
Go to the breakpoint view(where all breakpoints can be seen as a list), right click your breakpoint and click move breakpoint to user.
Go to a.framework and repeat step 1 and 2 but for your framework project.
Now switch back to project B and run the project on simulator/device.
You'll now see program stopping at the breakpoints set in the framework as well.
You can also add the entire library (networkLib) project into your project and link the library dynamically by adding dependency in project settings. So you can have all the source code within your project. So you can debug it in run time.
Use XCode Workspace when you deal with multiple framework projects. When you use a workspace, breakpoints will work and you can find your crash without loads of back and forth debugging. It will be much easier to manage your frameworks in the long run.
You should debug the project networkLib which outputs the framework separately. The framework do not have app like structure so a framework file within other project can't be debugged.