CocoaPod and Unit Tests for Swift Framework - ios

So I'm having trouble locating the definitive answer after trawling Cocoapods.org
I know Quick and Nimble are used for Unit Tests, at least for objective-C, however when creating a CocoaPod in Swift as a framework, I read somewhere there is only one choice, but what is that choice?
What is THE framework I have to use for my swift,framework cocoa pod to have it count as tested, as it's not XCTest obviously.

For a pure Swift CocoaPod you can use Quick/Nimble or XCTest. I recommend reading the excerpt here from CocoaPods.org in regards to creating a new Swift framework (including unit tests).
https://guides.cocoapods.org/making/using-pod-lib-create.html
I recently created a Swift CocoaPod using the "pod lib create" command and using only XCTest. Using the provided command line approach you can start a new project to include unit tests and a demo app, if desired and all the setup is handled for you. The only configuration I needed was to ensure the pod target had enable_testability = YES so that your unit tests can read your pod classes.

Related

How can I use a 3rd party Framework inside my CocoaTouchFramework and my consuming App?

I am developing an iOS App and a CocoaTouchFramework. The iOS App depends on the framework. My goal is to use a 3rd party Framework (in this case AlamoFire) inside my CocoaTouchFramework. According to this Stack Overflow link it is discouraged to have a Framework embed another framework. The way I understand it is that the consuming iOS App (the app which depends on the framework) needs to provide the 3rd party dependency and that my framework can reference that dependency. I don't know how to set this up in Xcode however. Here is what I have currently set up in Xcode:
AlamoFireApp is the actual App and AlamoFramework is my own Framework that will use AlamoFire to perform various network requests. I embedded the AlamoFire dependency into the App. How can I use AlamoFire in the Framework now? I've tried linking to AlamoFire from within the Framework (Adding Alamofire.framework) in the Link Binary With Libraries section) but I always get the No such module 'AlamoFire' error when I try to import AlamoFire in my Framework's classes.
Any help is appreciated.
#cbbcloud you can make your own cocoa pods using alamo fire. All you have to do is add them as dependency in pod spec. And then you can import the use the framework to build your framework.
Pod::Spec.new do |s|
s.name = 'YourFrameworkName'
//other info
s.dependency 'Alamofire'
end
If you are new to cocoapods , follow this link
https://guides.cocoapods.org/making/index.html
Ok I've found a way to do it. I was able to solve the problem by dragging the AlamoFire.Framework into my framework (in this case, AlamoFramework) in Xcode. The important part that makes this work is to check the 'Copy items if needed' checkbox.
After checking this, the compiler can resolve the Alamofire module and there are also no linker issues. However this approach seems to contradict the recommendation of Rob Napier in his answer to this question that states:
The only appropriate time to link dependencies is at the application layer.
I haven't done full-time iOS development for very long so if anyone has any input they can give to clear up this issue, that would be great. But my problem has been fixed for now so I can continue with development.

"Swift is not supported for static libraries" when testing cocoapod

Recently I started creating my pod in Swift. I used pod lib create command and declined offer to use Nimble/Quick as testing library because I hoped to use standard XCTest. However, when I try to run tests, build just fails with message Swift is not supported for static libraries.
I tried to reopen Xcode and clean project, not working.
What should I do in this situation?
Swift don't supported static libraries. If you create lib used objc so you have 2 ways (create static lib and write script for convert to framework) but if you write used swift only one.
So you need create pod. Just create framework in xcode and add files for configurate your project to pod. It't easy, for example you can watch this, I create pod after create project
For swift you need to have Cocoa Touch Framework

Use CocoaPods in a secondary Xcode project

I have an Xcode workspace that has two projects. The main project uses the second project as a static library. The main project is working fine with CocoaPods. In both projects I need to include AFNetworking. How can I set this up correctly?
PS: I am using unit test in the static library project so including AFNetworking headers wont be enough.
Since you are already using cocoapods, I thinks the best way is to become your secondary project a pod itself, a private one if you can not free the code. That way you can define in the podspec all the dependencies you need, like AFNetworking and when you use that in the main project all the dependencies will be managed for you.
Also that way unit testing and reusing should become even easier.

Stripe API gives 'SenTestingKit/SenTestingKit.h' file not found

I've read through the article referring to this in xcode 4.5, but it didn't help me in xcode 5.0.2.
I have a project that compiles successfully. If I add the Stripe framework to my project then it immediately fails to compile and gives me this file not found error for an #import made in this header file:
Stripe/Vendor/PaymentKit/PaymentKit Example/PaymentKit Test/PKCardNumberTest.h:9:9: 'SenTestingKit/SenTestingKit.h' file not found
I do not have the SenTesting framework in my link libraries. If I add it I get an error about it being an OSX library and not an ios. None of the Stripe documentation gives any indication that you need to add this library. I sent their support an email and they told me they don't have any information.
Anyone out there have any suggestions? Again, as soon as I add the framework to my project (and I am making sure it copies the files to my project) it fails to compile.
I tried adding quotes around my framework search paths, but it just changed the error so now Parse/Parse.h was no longer found.
The two framework search paths I have are: $(inherited) and /Users/ctam/Documents/development/Chw
See the Xcode 5.0 Release Notes:
Unit Testing
The CPlusTest unit testing framework has been removed
from Xcode 5. To write unit tests for C++ code, use the new XCTest
framework and create Objective-C++ (.mm) test case subclasses. 8273037
SenTestingKit and OCUnit are deprecated. Use the migrator to move to
XCTest. 14857574
When you download the Stripe library via the link in their documentation there are a bunch of subfolders for a test project they don't tell you about. I looked through and removed the test application files and everything works fine now. Curious that their explicit directions lead to this problem.

How to test an iOS Framework

I need to test an iOS Framework. I do not wish to test the UI. Is there any way to test just the Framework which would be used in the main Project?
If you just plan to test logical stuff, you can create new Unittest target for framework by using XCTest.framework. It is available in Xcode 5 and above. There are also third-party unittest frameworks. Check this out http://www.raywenderlich.com/3716/unit-testing-tutorial-for-ios-xcode-4-quick-start-guide

Resources