Code coverage shows you which of your app’s code paths are being tested. When you run a set of tests with code coverage enabled, Xcode tracks how many times each branch in your code is called. The test report shows a hierarchical view of test coverage for each file.
Click on the Test Navigator and add new Unit Test Target. For a higher code coverage aim to write unit tests for all functions you write throughout your application.
- Navigate to the Scheme Editor.
-
Click on Edit Scheme.
-
Select Options.
- Run your tests by clicking on the test or Cmd-U.
- Navigate to the Report Navigator.
- Select the lastest Test and click on Coverage to view all the code coverage for you app.
func testLoadFellows() {
// arrange
// 1
// first get an instance of the ViewController()
let viewController = ViewController()
// act
// 2
// load the view controller into memory
viewController.loadViewIfNeeded()
let fellows = viewController.fellows
// assert
XCTAssertEqual(fellows.count, 2)
}