[Technical Questions] How to write tests for codes executed only after getting HealthKit Data #68
-
In what area do you have a technical challenge?UI Testing related to HealthKit DescriptionHi, when I am developing the visualization for HealthKit data, I find it hard to test my codes to parse and plot the queried HealthKit data. For example, in the Codecov report (1 and 2 for this PR), we can see that the codes marked red (missing coverages) are all related to either reading the HealthKit query results, or plotting the HealthKit data. I wrote a simple UI test to check whether the dashboard is loaded as expected but missing coverage for those codes as I do not know whether there are HealthKit data available in PR and Codecov testing. Is there a desired way to test such codes (e.g. maybe manually input health data and check, or initialize those views directly with faked health kit data instead of starting the whole application in the UI tests, or could this be done with unit tests), and/or are there any examples for testing such codes? ReproductionThe issues could be viewed from the Codecov report (1, and 2). It is clearer in the second link that the functions marked red are just functions processing the fetched HealthKit data. Expected behaviorIf possible, I hope to have the codes tested possibly with faked HealthKit data. Thank you! 😄 Additional contextNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @YurenSUN, a great question! You can manually create a lot of the HealthKit data types and manually call the functions you want to call within a unit test. For those that you cannot create using code or when you need to do a full integration test: We have a dedicated packe for this: https://github.com/StanfordBDHG/XCTHealthKit. It allows you to run UI tested that add elements from the health app. |
Beta Was this translation helpful? Give feedback.
Hi @YurenSUN, a great question!
You can manually create a lot of the HealthKit data types and manually call the functions you want to call within a unit test.
E.g., you can create a simple HKSample like this: https://developer.apple.com/documentation/healthkit/hkquantitysample/1615016-init.
For those that you cannot create using code or when you need to do a full integration test: We have a dedicated packe for this: https://github.com/StanfordBDHG/XCTHealthKit. It allows you to run UI tested that add elements from the health app.