Exclude a class from unit test coverage

Setup:

  • In order to run unit tests, we have a bunch of mock JSON data that we use to test our parsing and data models.
  • Our team ships Frameworks (not the final application), so we put the JSON files in a “Demo Application” target. This ensures that we will never ship this test resource in our framework. However… now we run our unit tests in the Demo target, not the framework target.

Issue:

This means I get unit test coverage for Demo files… misleading at best for Management’s understanding of our unit test coverage.

In addition in some frameworks we have View Controllers best covered by UI / Integration tests. The company has dictated use of another tool for this purpose (NOT XCTest).

I would like to be able to indicate to The code coverage tool that a particular file or method or class is NOT to be considered for unit test coverage.


Any thoughts?

Replies

In situations like this I usually put my test data and code in my test target. I can then disable the Show Test Bundles checkbox to exclude that code from code coverage.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"