title: Use Local JSON file in Unit Test
body: <p>I have an app called "FFQuestions".  I use a local json file called <code>QA.json</code>.</p>
  
  <p>Is there any way I can <strong>use <code>QA.json</code> in my "FFQuestionsTests" folder files</strong> without recreating the file and dropping it in that folder?  Is it something I need to change with my code to get to it? Or is it something as simple as adding the Target Membership for "FFQuestionsTests"?</p>
  
  <p><em>This is my method for loading <code>QA.json</code>...</em></p>
  
  <pre><code>func loadJSONFromFile() -&gt; [String: Any]? {
      guard let url = Bundle.main.url(forResource: "QA", withExtension: "json") else {return nil}
      guard let data: Data = NSData(contentsOf: url) as Data? else {return nil}
  
      do {
          let object = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
          guard let dictionary = object as? [String: Any] else {return nil}
          return dictionary
      } catch  {
          print("Not parsed")
      }
  
      return nil
  }
  </code></pre>
  
  <p><em>even thought it might need to be done somewhat differently in Unit Test so I tried out...</em></p>
  
  <pre><code>func loadJSONFromTestsFile() -&gt; [String: Any]? {
      let testBundle = Bundle(for: type(of: self))
      let url = testBundle.url(forResource: "QA", withExtension: "json")
  
      guard let data: Data = NSData(contentsOf: url!) as Data? else {return nil}
  
      do {
          let object = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
          guard let dictionary = object as? [String: Any] else {return nil}
          print(dictionary)
          return dictionary
      } catch  {
          print("Not parsed")
      }
  
      return nil
  }
  </code></pre>
  
  <p>So that is what I've tried, but I'm still getting a <code>nil</code> crash.</p>