Skip to main content
On this page

Run iOS unit tests in VS Code with XCTest and Swift Testing

Run XCTest, Swift Testing and UI tests from the Test Explorer, with failures marked on the failing line.

Last updated

Run iOS unit tests in VS Code with one click. With KXApp, your iOS project's unit and UI tests show up in VS Code's Test Explorer (the beaker icon in the activity bar), and both XCTest and Swift Testing are supported. Tests run on the current run destination, a simulator or an iPhone; each test shows its result live, and failures are marked on the failing line.

How does VS Code find iOS unit tests?

Tests are grouped by target › class › method. Swift Testing @Test functions are listed too, including ones with a display name. A run button sits in the gutter next to each test, so you can run it right from the editor.

How do I run one iOS unit test, a class or a whole target?

  • Click the run button next to a method, a class or a whole target to run just that.
  • Tests run on the current run destination, a simulator or a device; UI tests run on devices too.
  • Each test shows started, passed or failed live while the run is in progress.
  • Failures are marked on the failing line, with the assertion message.

To run iOS unit tests in VS Code, the scheme needs a test action (test targets checked in Xcode's scheme editor). Which device the tests run on depends on the current run destination; switching it is covered in build and run iOS apps in VS Code.

Frequently asked questions

Can UI tests run on an iPhone?

Yes. Switch the run destination to a connected iPhone and UI tests run on the device, just like unit tests.

Are Swift Testing tests listed?

Yes. Swift Testing @Test functions, including ones with a display name, appear in the Test Explorer alongside XCTest methods, grouped by target.

Where do I see why a test failed?

In the source: the failure is marked on the failing line with the assertion message, and the test is marked as failed in the Test Explorer.

Why can't my scheme run tests?

Most likely the scheme has no test action. Check the test targets under the scheme's test action in Xcode's scheme editor, then run again from VS Code.

Next steps