Skip to content

Commit

Permalink
mirror the readme changs to the docc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskollmer committed Jan 20, 2025
1 parent 7c16632 commit b53bf96
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions Sources/XCTHealthKit/XCTHealthKit.docc/XCTHealthKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,45 @@ SPDX-License-Identifier: MIT

XCTHealthKit is an XCTest-based framework to test the creation of HealthKit samples using the Apple Health App on the iPhone simulator.

You can use XCTHealthKit in your UI tests.

## How To Use XCTHealthKit

You can use XCTHealthKit in your UI tests. The [API documentation](https://swiftpackageindex.com/StanfordBDHG/XCTHealthKit/documentation) provides a detailed overview of the public interface of XCTHealthKit.

The framework has the following functionalities:


### Add Mock Data Using the Apple Health App

Use the `XCTestCase`'s `exitAppAndOpenHealth(_: HealthAppDataType) throws` function passing in an `HealthAppDataType` instance to add mock data using the Apple Health app:
Use the `XCTestCase.launchAndAddSample(healthApp:_:) throws` function passing in an `NewHealthSampleInput` instance to add mock data using the Apple Health app:
```swift
import XCTest
import XCTHealthKit

class HealthKitUITests: XCTestCase {
func testAddMockData() throws {
let healthApp = XCUIApplication.healthApp()
try launchAndAddSample(healthApp: healthApp, .steps(value: 71))
try launchAndAddSample(healthApp: healthApp, .electrocardiogram())
}
}
```

Alternatively, the `XCTestCase.launchAndAddSamples(healthApp:_:) throws` function can be used to add multiple samples in a single call:
```swift
import XCTest
import XCTHealthKit

class HealthKitUITests: XCTestCase {
func testAddMockDataUsingTheAppleHealthApp() throws {
try exitAppAndOpenHealth(.electrocardiograms)
try exitAppAndOpenHealth(.steps)
try exitAppAndOpenHealth(.pushes)
try exitAppAndOpenHealth(.restingHeartRate)
try exitAppAndOpenHealth(.activeEnergy)
func testAddMockData() throws {
let healthApp = XCUIApplication.healthApp()
try launchAndAddSamples(healthApp: healthApp, [
.activeEnergy(),
.electrocardiogram(),
.pushes(value: 117),
.restingHeartRate(value: 91),
.steps()
])
}
}
```
Expand Down

0 comments on commit b53bf96

Please sign in to comment.