sam
sam

Reputation: 3511

WatchOS Unit Testing

I am building an app for Apple Watch and want to write a simple unit test. I looked around and didn't find a single way to add a unit testing bundle for watchOS code. Xcode supports unit tests for iOS, macOS and even tvOS but not for watchOS. Has anyone ever done it and if yes what is the trick?

Upvotes: 18

Views: 2543

Answers (3)

Josh Buhler
Josh Buhler

Reputation: 27678

As of Xcode 12.5 & watchOS 7.4, unit and UI tests targets can now be setup for watchOS apps.

Xcode now supports XCTest unit and UI tests for watchOS apps. When creating a new watchOS app, check the Include tests checkbox to add a unit and UI test target to the newly created project. For an existing project, add a unit or UI test target via File > New > Target, and then add the test target to the Test action of the WatchKit App scheme. To run the tests, select a watch simulator or device from the run destinations menu in the toolbar, and then choose Product > Test. Note that testing is supported on watchOS 7.4 or later.

Upvotes: 1

leogdion
leogdion

Reputation: 2350

This has been added to Xcode 12.5

Upvotes: 2

Jeff Kelley
Jeff Kelley

Reputation: 19071

No, watchOS does not currently (as of watchOS 3) support unit or UI testing. What you can do is cross-compile non-watchOS-specific code to a shared library, then unit test that on another platform.

Upvotes: 11

Related Questions