Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to enter characteristics; Swift 6 and strict concurrency #17

Merged
merged 6 commits into from
Jan 27, 2025

Conversation

lukaskollmer
Copy link
Member

@lukaskollmer lukaskollmer commented Jan 26, 2025

add ability to enter characteristics; Swift 6

♻️ Current situation & Problem

HealthKit allows users to manually enter so-called characteristics into the Health app (eg: date of birth, wheelchair use, blood type, etc), which can then be read by apps.
This PR adds a function which allows automated entry of these characteristics as part of a UI test.
Furthermore, this PR also updates both the XCTHealthKit package itself, as well as the associated UITests app to Swift 6

This PR also makes the onboarding handling a public function, so that test cases can make use of this part of the package, without having to also enter e.g. a sample.

⚙️ Release Notes

  • Added XCTestCase.launchHealthAppAndEnterCharacteristics(_:), to enter characteristics values into the health app
  • Made XCTestCase.handleHealthAppOnboardingIfNecessary(_:) public

📚 Documentation

The new code is documented.

✅ Testing

There is a test that enters values for all supported characteristics.

Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@lukaskollmer lukaskollmer changed the title add ability to enter characteristics add ability to enter characteristics; Swift 6 and strict concurrency Jan 26, 2025
Copy link

codecov bot commented Jan 26, 2025

Codecov Report

Attention: Patch coverage is 75.54585% with 56 lines in your changes missing coverage. Please review.

Project coverage is 78.43%. Comparing base (e3e319e) to head (d1089fb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rces/XCTHealthKit/XCTest+CharacteristicEntry.swift 81.21% 28 Missing ⚠️
Sources/XCTHealthKit/XCTest+HealthApp.swift 62.17% 28 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
+ Coverage   75.98%   78.43%   +2.45%     
==========================================
  Files           5        7       +2     
  Lines         383      547     +164     
==========================================
+ Hits          291      429     +138     
- Misses         92      118      +26     
Files with missing lines Coverage Δ
Sources/XCTHealthKit/HealthAppCategory.swift 70.22% <ø> (ø)
Sources/XCTHealthKit/HealthAppSampleType.swift 87.50% <ø> (ø)
...rces/XCTHealthKit/XCTHealthKitAddSampleInput.swift 80.12% <100.00%> (+0.12%) ⬆️
Sources/XCTHealthKit/XCTest+AddSamples.swift 97.23% <100.00%> (+29.52%) ⬆️
Sources/XCTHealthKit/XCTest+HealthKit.swift 75.76% <100.00%> (ø)
...rces/XCTHealthKit/XCTest+CharacteristicEntry.swift 81.21% <81.21%> (ø)
Sources/XCTHealthKit/XCTest+HealthApp.swift 62.17% <62.17%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3e319e...d1089fb. Read the comment docs.

Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates; looks great!

I am wondering if we should (not here but at some point) add a prebuilt Button in a separate target here that writes a set of values in HealthKit from within the SUT (asks for write permissions and just reuses the structures we already have in this target to we share the same configuration as if we would enter them in the user interface) as well as a nice function into the XCTHealthKit target that the presses this button and handles the authentication flow. Might be worth it for some apps that don't want to follow the UI testing route as we also use that in SpeziHealthKit?

@PSchmiedmayer PSchmiedmayer added bug Something isn't working enhancement New feature or request labels Jan 27, 2025
@lukaskollmer
Copy link
Member Author

@PSchmiedmayer

Thank you for the updates; looks great!

I am wondering if we should (not here but at some point) add a prebuilt Button in a separate target here that writes a set of values in HealthKit from within the SUT (asks for write permissions and just reuses the structures we already have in this target to we share the same configuration as if we would enter them in the user interface) as well as a nice function into the XCTHealthKit target that the presses this button and handles the authentication flow. Might be worth it for some apps that don't want to follow the UI testing route as we also use that in SpeziHealthKit?

I thought about this as well, but my take (and the reason why i haven't done it so far) would be that the step of programmatically adding Health samples is actually super simple, and can trivially be done directly in the SUT, which would also allow the SUT much more control over the actual samples being created. (Unless our button would allow callers to specify this (eg: have a SampleDefinition type for specifying sample types, values, units, dates, etc), in which case we'd kinda end up unnecessarily recreating part of HealthKit via this mechanism.)
In many cases you probably also can't / don't want to add extra elements to your apps UI (think eg UI-testing a "real" app instead of our dedicated UITest apps), so in that case you'd probably still need the ability to enter samples directly via the Health App, unless you're fine with your app's UI when being UI-tested actually being slightly different from what real-world users would interact with.

I'm also not yet 100% sure what, if any, the differences between manually-entered Health data and programatically-entered data are (or for example whether there's a difference between data programmatically added in the current app vs programatically entered by some other app which happens to be in the background)

@lukaskollmer lukaskollmer merged commit 416637a into main Jan 27, 2025
7 checks passed
@lukaskollmer lukaskollmer deleted the lukas/characteristics-entry branch January 27, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants