How to reliably install and setup Quick test framework on Xcode 8?
Asked Answered
S

3

1

Background:
While working on this answer I noticed that it's not so trivial to properly set up Quick test framework on Xcode properly. In my case, it took 3-4 failed attempts to finally have a working version. And still, I'm not sure where my previous attempts were wrong. Or more importantly why the questioner in that thread could have duplicate run each time. Then it also took him several attempts to finally have a working one.

Question:
I am asking if any of you have a reliable way to set up Quick Framework on Xcode using Cocoa pods (or Carthage or Git Submodule), up to running a properly working Quick test case, that you're willing to share.

How I did it before:
Here is how I created my working Quick framework on Xcode:
1. I follow the step in XCTest article in RayWenderlich site to set up XCTest environment.
2. Then I add the Cocoa Pods as per installing Quick
3. Then follow instruction in Setting up your Xcode
4. Then I hacked and improvise all the rest of the way, googling for each issue I encounter after that, try this and that until it works.
(Among those steps include add Quick framework to link binary in build phase of my target)

I'm not proud to share my steps above, but I don't have a better way for now. I hope to find a better way by asking this question. It might be too much to ask.

My Podfile :

target 'PlayQuick' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for PlayQuick

target 'PlayQuickTests' do
    inherit! :search_paths
    # Pods for testing
    pod 'Quick'
    pod 'Nimble' 
end

end
Souza answered 29/5, 2017 at 14:28 Comment(3)
It should work without manual setup steps in Xcode, can you share your Podfile please?Harris
I've updated my question above with the content of the Podfile.Souza
To add; I encountered 2 similar, yet different problems. The first is already known; why the examples get called multiple times (described here: #44044933). The second problem is that Xcode occasionally fails to find the framework. Though this can be solved by building the framework first, then your project; occasionally this method fails and I've got no clue why.Narcoma
W
1

Git submodule way is the most lean and simple way to achieve that.

Follow the these steps to start from zero:

1.a. Create Xcode project with Include Unit Tests checked.

1.b. Alternatively, you could create unit test target on existing project.

  • Open test Navigator.
  • Click the + button in the lower-left corner, then select New Unit Test Target… from the menu:


2. Close the Xcode project in (1)

3. Create new Xcode workspace. File -> New -> Workspace.

4. Open Terminal / Bash Shell / Cmd.exe

5. Create a new sub directory for GitHubProjectClones.

  • for example: $HOME/Developer/GitHubProjectClones


6. cd to sub directory in (5):

  • mkdir Vendor
  • git init


7. Follow step one in Git Submodule section


8. Follow step two in Git Submodule section.

  • Back to Xcode with Workspace open:
    • Make sure Project Navigator is selected
      • File -> Add files to:
        • select the Quick folder created in step 7.
      • File -> Add files to:
        • select the Nimble folder created in step 7.
      • File -> Add files to:
        • select your Xcode project in step 1.


9. Follow step three in Git Submodule section to link Quick.framework and Nimble.framework during your test target's Link Binary with Library build phase.

10. You should be able to follow along the examples in Quick Documentation

Weismannism answered 30/5, 2017 at 13:31 Comment(1)
This shall be more lean and error-safe than integrating libs with cocoapods? I don't think so, sorry. Way too many manual actions involved. No version management. No automatic project integration...Harris
H
1

Integrating Quick & Nimble via cocoapods works for me out of the box with no problems (macOS Sierra, Xcode8.3.2, iOS 10.3 SDK, Swift 3.1, cocoapods 1.2.1).

Be sure to have the latest stable cocoapods version installed (gem update cocoapods) and to call pod install and not just pod update. You can also try to reintegrate your pods from scratch by calling pod deintegrate && pod install.

Maybe there is an odd build setting or something similar in your project. You could validate this with a virgin test project.

If nothing seems to work, you should upload your project (e.g. to GitHub) so the community will be able to pinpoint the problem.

Harris answered 30/5, 2017 at 8:14 Comment(4)
I've uploaded the failed attempt to install Quick using Cocoapods way at: github.com/Shisui-U/TryQuickCocoaPodsWay1 The steps are similar to the steps detailed by Mikasa, except step 5-9, where I used the pods command you mentioned above. gem update cocoapods ; pod init ; vi Podfile ; pod install then open the xcworkspace in Xcode. The error message is Quick module not found.Souza
Thanks Shisui. I'm on vacation and can't check the project right now. Xcode should find the Quick Framework if you just build the pod / project for one time (CMD+B). The initial finding problem is related to an odd behavior of the indexer / compiler front end parserHarris
Enjoy your vacation, Sven. When you're back, you could check the project. I tried the Product-> Clean (Shfit-CMD-K) then Product -> Build (CMD+B), And I got this error: clang: error: linker command failed with exit code 1 (use -v to see invocation)Souza
From the Report Navigator window, I got: ld: framework not found Pods_TryQuickCocoaPodsWay clang: error: linker command failed with exit code 1 (use -v to see invocation)Souza
W
1

Git submodule way is the most lean and simple way to achieve that.

Follow the these steps to start from zero:

1.a. Create Xcode project with Include Unit Tests checked.

1.b. Alternatively, you could create unit test target on existing project.

  • Open test Navigator.
  • Click the + button in the lower-left corner, then select New Unit Test Target… from the menu:


2. Close the Xcode project in (1)

3. Create new Xcode workspace. File -> New -> Workspace.

4. Open Terminal / Bash Shell / Cmd.exe

5. Create a new sub directory for GitHubProjectClones.

  • for example: $HOME/Developer/GitHubProjectClones


6. cd to sub directory in (5):

  • mkdir Vendor
  • git init


7. Follow step one in Git Submodule section


8. Follow step two in Git Submodule section.

  • Back to Xcode with Workspace open:
    • Make sure Project Navigator is selected
      • File -> Add files to:
        • select the Quick folder created in step 7.
      • File -> Add files to:
        • select the Nimble folder created in step 7.
      • File -> Add files to:
        • select your Xcode project in step 1.


9. Follow step three in Git Submodule section to link Quick.framework and Nimble.framework during your test target's Link Binary with Library build phase.

10. You should be able to follow along the examples in Quick Documentation

Weismannism answered 30/5, 2017 at 13:31 Comment(1)
This shall be more lean and error-safe than integrating libs with cocoapods? I don't think so, sorry. Way too many manual actions involved. No version management. No automatic project integration...Harris
S
1

Follow the steps to reliable setup of Quick and Nimble:

Prerequisites:

cocoapods installed in your machine (installation Guide)

1) create a new Xcode project

Xcode—> File —> New —> Project

2) Select Single View App (Normally most of the application use this) —>Next

  • Enter Product Name (App NAme) - (here we are using WeatherForecast)

  • enable check mark for Include Unit Tests

3 )Installation

Open terminal

Move to your working directory cd (path of your project folder)

Ex: enter in terminal cd /Users/Documents/ WeatherForecast

4) Initialise pods with

Pod init

5) Open the newly created Podfile within your favourite text editor.

edit podfile with below contents

platform :ios, '9.0'

target WeatherForecast’ do

  use_frameworks!

  # Pods for WeatherForecast

  target 'WeatherForecastTests' do

    inherit! :search_paths

    # Pods for testing

    pod 'Quick'

    pod 'Nimble'

  end

5) Save the podfile.Return to terminal and

enter pod install in terminal

6) This will install your new frameworks and create a pods project. It will also generate a workspace. You should now use the new workspace when working on your project. So if you’ve opened your project already close it and in open the WeatherForecasr.xcworkspace instead.

7) Setting up your test class

Within your tests target create a new group and file by: Highlighting WeatherForecast Tests.

File —>New—> Group

Rename the new Group ModelTests

Highlight your new group

File —>New —> File

Select Swift file, Press Next

  • Name the new file CurrentSpecs . Press create

7) Within your new file replace the contents with the following

import Foundation

import Quick

import Nimble

@testable import WeatherForecast

class CurrentWeatherSpecs: QuickSpec {

}

*After this you might face an error

“No such Module Quick”

“No such Module Nimble”

Below steps worked to Fix the error

Try the Following:

  1. open Xcode schemes list

  2. tick Nimble and Quick with “show” and close.

  3. Select Nimble as a scheme and build (cmd + B)

  4. Select Quick as a scheme and build(cmd+B)

  5. Change scheme back to your app scheme and see if the error is gone and autocompletion works

This is what I have to do from time to time

Suellen answered 10/5, 2020 at 18:25 Comment(2)
Please use the code highlighting feature for all of your code. ThanksScatterbrain
@NicoS. Thank you for suggestingSuellen

© 2022 - 2024 — McMap. All rights reserved.