Use resources in unit tests with Swift Package Manager

前端 未结 7 513
孤街浪徒
孤街浪徒 2020-12-08 21:12

I\'m trying to use a resource file in unit tests and access it with Bundle.path, but it returns nil.

This call in MyProjectTests.swift returns nil:

7条回答
  •  悲哀的现实
    2020-12-08 21:33

    A made a simple solution that works for legacy swift and future swift:

    1. Add your assets in the root of your project
    2. In your swift code: ResourceHelper.projectRootURL(projectRef: #file, fileName: "temp.bundle/payload.json").path
    3. Works in Xcode and swift build in terminal or github actions

提交回复
热议问题