mardi 1 décembre 2015

Unit Test HKSampleQuery in Swift

When I need to read data from HealthKit this is how my code looks like:

let stepsCount = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)

let stepsSampleQuery = HKSampleQuery(sampleType: stepsCount,
    predicate: nil,
    limit: 100,
    sortDescriptors: nil)
    { [unowned self] (query, results, error) in
        if let results = results as? [HKQuantitySample] {
            self.steps = results
            // Update some UI
        }
        self.activityIndicator.stopAnimating()
}

healthStore?.executeQuery(stepsSampleQuery)

This specific code was extracted from here for demo purpose.

So my question is:

How can I unit test this kind of code ?

Aucun commentaire:

Enregistrer un commentaire