Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CDC Testing on iOS

giginet
September 13, 2016

CDC Testing on iOS

We integrated Pact for iOS applications.

http://cookpad-tech-kitchen.connpass.com/event/37908/

giginet

September 13, 2016
Tweet

More Decks by giginet

Other Decks in Technology

Transcript

  1. ༻ޠ • Provider • APIΛఏڙ͢Δଆ = APIαʔόʔ • Consumer •

    APIΛར༻͢Δଆ = iOSΞϓϦ • Contract • APIͷ࢓༷
  2. $POTVNFS ϞόΠϧΞϓϦ 1SPWJEFS "1* #SPLFS HTTP Request HTTP Response Pact

    file ϦΫΤετͱϨεϙϯεΛBrokerʹه࿥͢Δ
  3. $POTVNFS ϞόΠϧΞϓϦ 1SPWJEFS "1* #SPLFS HTTP Request HTTP Response Pact

    file Pact fileʹهड़ͨ͠ϦΫΤετΛ౤͛ͯݕূ͢Δ
  4. import Foundation import XCTest import Phakchi class RecipeSearchPact: XCTest {

    var session: Session! override func setUp() { super.setUp() let expectation = expectationWithDescription("Set up Pact environment") controlServer.startSession(withConsumerName: "Cookpad", providerName: "APIServer") { newSession in if let newSession = newSession { self.session = newSession expectation.fulfill() } } waitForExpectationsWithTimeout(3.0) } }
  5. func testSearchRecipe() { let manager = RecipeManager(baseURL: session.baseURL) let expected

    = [ "recipes": [ ["name": "େτϩ", "description": "ඒຯ͍"], ["name": "͏ʹ", "description": “ඒຯ͍"], ] ] // Interactionͷొ࿥ let expectation = expectationWithDescription("recipes are found") session.given("some recipes exist") // Provider State .uponReceiving("a request for recipes") .with(method: .GET, path: "/recipes", query: [ "keyword": "ण࢘", ]) .willRespondWith(status: 200, body: expected)
  6. func testSearchRecipe() { let manager = RecipeManager(baseURL: session.baseURL) let expected

    = [ "recipes": [ ["name": "େτϩ", "description": "ඒຯ͍"], ["name": "͏ʹ", "description": “ඒຯ͍"], ] ] // Interactionͷొ࿥ let expectation = expectationWithDescription("recipes are found") session.given("some recipes exist") // Provider State .uponReceiving("a request for recipes") .with(method: .GET, path: "/recipes", query: [ "keyword": "ण࢘", ]) .willRespondWith(status: 200, body: expected)
  7. func testSearchRecipe() { let manager = RecipeManager(baseURL: session.baseURL) let expected

    = [ "recipes": [ ["name": "େτϩ", "description": "ඒຯ͍"], ["name": "͏ʹ", "description": “ඒຯ͍"], ] ] // Interactionͷొ࿥ let expectation = expectationWithDescription("recipes are found") session.given("some recipes exist") // Provider State .uponReceiving("a request for recipes") .with(method: .GET, path: "/recipes", query: [ "keyword": "ण࢘", ]) .willRespondWith(status: 200, body: expected)
  8. session.run(completionBlock: { isValid in // completeTest࣮ߦޙʹݺ͹ΕΔ XCTAssertTrue(isValid) expectation.fulfill() }) {

    completeTest in // APIϦΫΤετΛૹΔ manager.fetchRecipes(from: ”ण࢘") { (recipes, error) in XCTAssertEqual(recipes.count, 2) XCTAssertNil(error) XCTAssertEqual(recipes[0].name, "େτϩ") XCTAssertEqual(recipes[0].description, "ඒຯ͍") XCTAssertEqual(recipes[1].name, "͏ʹ") XCTAssertEqual(recipes[1].description, "ඒຯ͍") completeTest() // Mock ServerʹϨεϙϯε͕ਖ਼͍͜͠ͱΛ௨஌ } }) waitForExpectationsWithTimeout(3.0) }
  9. session.run(completionBlock: { isValid in // completeTest࣮ߦޙʹݺ͹ΕΔ XCTAssertTrue(isValid) expectation.fulfill() }) {

    completeTest in // APIϦΫΤετΛૹΔ manager.fetchRecipes(from: ”ण࢘") { (recipes, error) in XCTAssertEqual(recipes.count, 2) XCTAssertNil(error) XCTAssertEqual(recipes[0].name, "େτϩ") XCTAssertEqual(recipes[0].description, "ඒຯ͍") XCTAssertEqual(recipes[1].name, "͏ʹ") XCTAssertEqual(recipes[1].description, "ඒຯ͍") completeTest() // Mock ServerʹϨεϙϯε͕ਖ਼͍͜͠ͱΛ௨஌ } }) waitForExpectationsWithTimeout(3.0) }
  10. session.run(completionBlock: { isValid in // completeTest࣮ߦޙʹݺ͹ΕΔ XCTAssertTrue(isValid) expectation.fulfill() }) {

    completeTest in // APIϦΫΤετΛૹΔ manager.fetchRecipes(from: ”ण࢘") { (recipes, error) in XCTAssertEqual(recipes.count, 2) XCTAssertNil(error) XCTAssertEqual(recipes[0].name, "େτϩ") XCTAssertEqual(recipes[0].description, "ඒຯ͍") XCTAssertEqual(recipes[1].name, "͏ʹ") XCTAssertEqual(recipes[1].description, "ඒຯ͍") completeTest() // Mock ServerʹϨεϙϯε͕ਖ਼͍͜͠ͱΛ௨஌ } }) waitForExpectationsWithTimeout(3.0) }
  11. import Foundation import XCTest import Phakchi class RecipeSearchPact: XCTest {

    var session: Session! override func setUp() { super.setUp() let expectation = expectationWithDescription("Set up Pact environment") // ϞοΫαʔόʔͷॳظԽ controlServer.startSession(withConsumerName: "Cookpad", providerName: "APIServer") { newSession in if let newSession = newSession { self.session = newSession expectation.fulfill() } } waitForExpectationsWithTimeout(3.0) } func testSearchRecipe() { let manager = RecipeManager(baseURL: session.baseURL) let expected = [ "recipes": [ ["name": "େτϩ", "description": "ඒຯ͍"], ["name": "͏ʹ", "description": "ඒຯ͍"], ] ] // Interactionͷొ࿥ let expectation = expectationWithDescription("recipes are found") session.given("some recipes exist") // Provider State .uponReceiving("a request for recipes") .with(method: .GET, path: "/recipes", query: [ "keyword": "ण࢘", ]) .willRespondWith(status: 200, body: expected) session.run(completionBlock: { isValid in // completeTest࣮ߦޙʹݺ͹ΕΔ XCTAssertTrue(isValid) expectation.fulfill() }) { completeTest in // APIϦΫΤετΛૹΔ manager.fetchRecipesFromKeyword("ण࢘") { (recipes, error) in XCTAssertEqual(recipes.count, 2) XCTAssertNil(error) XCTAssertEqual(recipes[0].name, "େτϩ") XCTAssertEqual(recipes[0].description, "ඒຯ͍") XCTAssertEqual(recipes[1].name, "͏ʹ") XCTAssertEqual(recipes[1].description, "ඒຯ͍") completeTest() // Mock ServerʹϨεϙϯε͕ਖ਼͍͜͠ͱΛ௨஌ } }) waitForExpectationsWithTimeout(3.0) } }
  12. $POTVNFS ϞόΠϧΞϓϦ 1SPWJEFS "1* #SPLFS HTTP Request HTTP Response Pact

    file Pact fileʹهड़ͨ͠ϦΫΤετΛ౤͛ͯݕূ͢Δ