Integrate Cuckoo With SwiftPM

Library reference can be found in below link : https://github.com/Brightify/Cuckoo

Steps to integrate Library in iOS project.

  1. Open Xcode create new project by : File -> New -> Project. Give it some nice name like FirstMockSampleProject. Do not forget to click on include Tests.

2. Now, Click on File -> Swift Packages -> Add Package Dependency. This will open a window for asking framework source url. Give the git url and then click on next it will ask up to which version we needed, Enter version then again click on next it will download the the library and finally click on Finish.

Great now dependency is added in project via Swift Package Manager.

3. Now we need to add a run script in project which you can also found in source link of library. Also available below :

# Define output file. Change "${PROJECT_DIR}/${PROJECT_NAME}Tests" to your test's root source folder, if it's not the default name.OUTPUT_FILE="${PROJECT_DIR}/${PROJECT_NAME}Tests/GeneratedMocks.swift"echo "Generated Mocks File = ${OUTPUT_FILE}"# Define input directory. Change "${PROJECT_DIR}/${PROJECT_NAME}" to your project's root source folder, if it's not the default name.INPUT_DIR="${PROJECT_DIR}/${PROJECT_NAME}"echo "Mocks Input Directory = ${INPUT_DIR}"# Generate mock files, include as many input files as you'd like to create mocks for."${PROJECT_DIR}/run" --download generate --testable "${PROJECT_NAME}" \--output "${OUTPUT_FILE}" \"${INPUT_DIR}/{path of file name that need to be mock}.swift" \

Although there are multiple ways to add run script in project.

Let’s discuss two of these.

3.1 Click on test target build phases and then add new run script phase. (every time when you need to mock new file project is also get changed because script in written in project file)

3.2 Create a script file CuckooScript.sh in test bundle and give the path of the script file in new run script phase. (Project file remain unchanged when any new file need to mock since script is available outside of project file)

You can choose any way based on your requirement.

4. Now, Build the project for testing after this a file with name GeneratedMocks.swift will be created on given path, add this file in test target.

After all above steps you have successfully integrated cuckoo library in your project. In next article, I will let you know how to write first test case by mocking dependencies.

iOS developer