# FindXCTest

Added in version 3.3.

Finds the XCTest framework for writing unit tests in Xcode projects:

    find_package(XCTest [...])

Note

Xcode 16 and later includes the Swift Testing framework for writing unit tests in the Swift programming language, which supersedes XCTest.

An XCTest bundle is a CFBundle (Core Foundation Bundle) with a special product type and bundle extension. See the Apple Developer Library for more information in the Testing with Xcode documentation.

## Result Variables

This module defines the following variables:

`XCTest_FOUND`

  Boolean indicating whether the XCTest framework and executable were found.

`XCTest_INCLUDE_DIRS`

  Include directories containing the XCTest framework headers needed to use XCTest.

`XCTest_LIBRARIES`

  Libraries needed to link against to use XCTest framework.

## Cache Variables

The following cache variables may also be set:

`XCTest_EXECUTABLE`

  The path to the `xctest` command-line tool used to execute XCTest bundles.

## Commands

When XCTest is found, this module provides the following commands to help create and run XCTest bundles:

xctest_add_bundle

  Creates an XCTest bundle to test a given target:

      xctest_add_bundle(<bundle> <testee> [<sources>...])

  This command creates an XCTest bundle named `<bundle>` that will test the specified `<testee>` target.

  The arguments are:

  `<bundle>`

    Name of the XCTest bundle to create. The `XCTEST` target property will be set on this bundle.

  `<testee>`

    Name of the target to test. Supported types for the testee are Frameworks and App Bundles.

  `<sources>...`

    One or more source files to add to the bundle. If not provided, they must be added later using commands like `target_sources()`.

  Note

  The `CMAKE_OSX_SYSROOT` variable must be set before using this command.

xctest_add_test

  Adds an XCTest bundle to the project to be run during the CTest phase:

      xctest_add_test(<name> <bundle>)

  This command registers an XCTest bundle to be executed by `ctest(1)`. The test will be named `<name>` and will run the specified `<bundle>`.

  The arguments are:

  `<name>`

    Name of the test as it will appear in CTest.

  `<bundle>`

    Target name of the XCTest bundle.

## Examples

Finding XCTest and adding tests:

    find_package(XCTest)

    add_library(foo SHARED foo.c)

    if(XCTest_FOUND)
      xctest_add_bundle(TestAppBundle foo source.swift)
      xctest_add_test(app.TestAppBundle TestAppBundle)
    endif()