title: Unit test is incorrectly executing code from the launch view controller
body: <p>I have a simple struct as below which is part of an iOS Application:</p>
  
  <pre><code>struct Country: JSONObject {
      let name: String!
      let code: String!
  
      static let nameKey = "name"
      static let codeKey = "dial_code"
  
      init?(_ json: [String: AnyObject]) throws {
          guard let name = json[Country.nameKey] as? String else {
             throw JSONError.InvalidTypeForKey(key: Country.nameKey)
          }
  
          guard let code = json[Country.codeKey] as? String else {
              throw JSONError.InvalidTypeForKey(key: Country.codeKey)
          }
  
          self.name = name
          self.code = code
      }
  }
  </code></pre>
  
  <p>I wrote a unit test to test initialisation of this class:</p>
  
  <pre><code>func testCorrectInitialisationOfCountry() {
      let countryDict = [Country.nameKey: "England", Country.codeKey: "+44"]
  
      do {
          let country = try Country(countryDict)!
          XCTAssert(countryDict[Country.nameKey] == country.name, "The country name does not match")
          XCTAssert(countryDict[Country.codeKey] == country.code, "The country code does not match")
      }
      catch _ {
          print("Initialisation of country failed with an exception")
      }
  }
  </code></pre>
  
  <p>The problem I am facing is this struct is initialised several times in the viewDidLoad() method in the first view controller of my app.</p>
  
  <p>For some reason, that viewDidLoad() method is being called when I run my tests and generating incorrect code coverage because of that. The picture below shows the unit test stats generated by Xcode.</p>
  
  <p><a href="https://i.stack.imgur.com/ZJJF9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZJJF9.png" alt="enter image description here"></a></p>
  
  <p>The numbers "241" should actually be just "1". The other 240 times, that line is being executed from the launch view controller which is not under test.</p>
  
  <p>How can I stop the view controller code from executing?</p>
  
  <p>Thanks in advance.</p>