Use resources in unit tests with Swift Package Manager

前端 未结 7 481
孤街浪徒
孤街浪徒 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:43

    starting on Swift 5.3, thanks to SE-0271, you can add bundle resources on swift package manager by adding resources on your .target declaration.

    example:

    .target(
       name: "HelloWorldProgram",
       dependencies: [], 
       resources: [.process(Images), .process("README.md")]
    )
    

    if you want to learn more, I have written an article on medium, discussing this topic. I don't specifically discuss .testTarget, but looking on the swift proposal, it looks alike.

    0 讨论(0)
提交回复
热议问题