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

1.5k views Asked by At

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
3

There are 3 answers

1
Mikasa On BEST ANSWER

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

4
Sven Driemecker On

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.

2
Pratima On

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