Skip to content

Instantly share code, notes, and snippets.

@psturc
Last active April 10, 2018 08:10
Show Gist options
  • Save psturc/a463ecc5e2a6bebcaaa964e0c75eb91d to your computer and use it in GitHub Desktop.
Save psturc/a463ecc5e2a6bebcaaa964e0c75eb91d to your computer and use it in GitHub Desktop.
metrics integration testing
/*
To run those tests from commandline:
xcodebuild \
-workspace example/AeroGearSdkExample.xcworkspace \
-scheme AeroGearSdkExampleTests -sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 7' \
'-only-testing:AeroGearSdkExampleTests/MetricsIntegrationTests/_testPublishingDefaultMetricsShouldNotReturnError' \
'-only-testing:AeroGearSdkExampleTests/MetricsIntegrationTests/_testPublishingInvalidMetricsShouldReturnError' \
test CODE_SIGNING_REQUIRED=NO
**/
@testable import AGSCore
import Foundation
import XCTest
class MetricsIntegrationTests: XCTestCase {
let metrics = AgsCore.instance.getMetrics()
func _testPublishingDefaultMetricsShouldNotReturnError () {
let expectation = XCTestExpectation(description: "Getting Success statusCode from App Metrics after sending device and app metrics")
metrics.publish([DeviceMetrics(), AppMetrics(AgsCore.getMetadata())], { (response: AgsHttpResponse?) -> Void in
XCTAssertNil(response?.error, "Expecting no error from response after sending valid metrics")
if let statusCode = response?.statusCode {
XCTAssert(statusCode < 300, "Expecting returned statusCode to be success (2xx), but it was \(statusCode)")
}
expectation.fulfill()
})
wait(for: [expectation], timeout: 10.0)
}
func _testPublishingInvalidMetricsShouldReturnError () {
let expectation = XCTestExpectation(description: "Getting Server error from App Metrics after sending invalid (empty) metrics")
metrics.publish([], { (response: AgsHttpResponse?) -> Void in
if let statusCode = response?.statusCode {
XCTAssert(statusCode == 400, "Expecting returned statusCode to be 400, but it was \(statusCode)")
}
expectation.fulfill()
})
wait(for: [expectation], timeout: 10.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment