Skip to content

Instantly share code, notes, and snippets.

@SergioEstevao
Created April 11, 2016 15:13
Show Gist options
  • Save SergioEstevao/586fa2ba970ceeed3c18890fe4c5f219 to your computer and use it in GitHub Desktop.
Save SergioEstevao/586fa2ba970ceeed3c18890fe4c5f219 to your computer and use it in GitHub Desktop.
import XCTest
import cloudup
class JSONObjectTest: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testJSONObjectSuccessfullReading() {
guard let jsonURL = NSBundle(forClass: self.dynamicType).URLForResource("test", withExtension: "json"),
let data = NSData(contentsOfURL: jsonURL),
let jsonObject = try? JSONObject(data: data) else {
XCTFail("Unable to read mock data")
return
}
do {
let aString = try jsonObject.dictionary("string").string()
XCTAssertEqual(aString, "A string", "A string should be found")
let aInteger = try jsonObject.dictionary("integer").integer()
XCTAssertEqual(aInteger, 1, "A integer should be found")
let aDouble = try jsonObject.dictionary("double").double()
XCTAssertEqual(aDouble, 3.14, "A double should be found")
let aNull = try jsonObject.dictionary("null").null()
XCTAssertEqual(aNull, NSNull(), "A null should be found")
} catch {
XCTFail("This code shouldn't throw any exception")
}
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
// Put the code you want to measure the time of here.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment