0

guard will be triggered, and file not loaded, what can I do?

final class IkigaJSONTests: XCTestCase {    
    func testConst() {
        guard let filepath = Bundle.main.path(forResource: "const", ofType: "json"), let schemaStr = try? String(contentsOfFile: filepath) else { // <-------
            XCTFail()
            return
        }

file is added:

enter image description here

Tried this, did not work: How to include a file in Test Bundle swift?

Here, this also not good, and when adding not Xcode does not ask to add to bundle

    func testConst() {
        let bundle = Bundle(for: IkigaJSONTests.self)
        guard let filepath = bundle.path(forResource: "const", ofType: "json"), let schemaStr = try? String(contentsOfFile: filepath) else {
            XCTFail()
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Alma
  • 31
  • 4

0 Answers0