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

アプリを十数個作った僕が初めて書いたテストの話

ryokosuge
March 26, 2018

 アプリを十数個作った僕が初めて書いたテストの話

iOS Test Night #7で発表させて頂きました。

ryokosuge

March 26, 2018
Tweet

More Decks by ryokosuge

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ ๏খੁɹྒʢ28ʣ ๏Nagisa, inc. ๏ ອըPFࣄۀ෦ ๏ ϚϯΨZERO ๏ iOSΤϯδχΞ

    ๏ςετྺ ๏ ̐ϲ݄ ๏Social ๏ Twitter: @ryo_kosuge ๏ Github: ryokosuge
  2. Swift4ͰCodable࢖ͬͯΈͨ ๏ ࠓ·ͰAPIKit & Himotoki ๏ JSONͷdecodeॲཧΛओʹ ๏ ॻ͖ํ͸άάΕ͹ग़ͯ͘Δ͕ɺ͍͋ͬͯΔ͔Θ͔Βͳ͍... ๏

    ؒҧͬͨ·Μ·mergeͯ͠࢖͔ͬͯΒमਖ਼͢ΔͷͰ͸஗͍ ๏ merge͢Δͱ͖͸׬શʹػೳ͢Δ͜ͱΛ໿ଋ͍ͯ͠Δ΂͖ -> ςετ͕ඞਢʂʂ
  3. ॻ͍ͨςετίʔυ public struct Person: Codable { enum CodingKeys: String, CodingKey

    { case firstName = "first_name" case lastName = "last_name" } public let firstName: String public let lastName: String }
  4. ॻ͍ͨςετίʔυ import XCTest class PersonTests: XCTestCase { /// σίʔυॲཧ͕ग़དྷΔ͔Ͳ͏͔ func

    testsDecode() { let decoder = JSONDecoder() let value = "{\"first_name\": \"kosuge\", \"last_name\": \"ryo\"}" do { let object = try decoder.decode(Person.self, from: value.data(using: .utf8)!) print(object) } catch let e { XCTFail(e.localizedDescription) } } }
  5. ॻ͍ͨςετίʔυ import XCTest class PersonTests: XCTestCase { /// ஋͕଍Γͣɺσίʔυॲཧʹࣦഊ͢Δ͔Ͳ͏͔ func

    testsFailDecode() { let decoder = JSONDecoder() let value = "{\"first_name\": \"kosuge\"}" let object = try? decoder.decode(Person.self, from: value.data(using: .utf8)!) XCTAssertNil(object) // nil͡Όͳ͖Ό͍͚ͳ͍ } }