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

Quickで体験するテストの構造化

laiso
January 19, 2017

 Quickで体験するテストの構造化

iOS Test Night #2
https://testnight.connpass.com/event/45717/

[テストの書き方、Quickの使い方](https://github.com/Quick/Quick/tree/master/Documentation/ja)
[Better Specs \{ rspec guidelines with ruby \}](http://betterspecs.org/jp/)
[私はRSpecでテストをこんな感じで書いてる](http://d.hatena.ne.jp/sinsoku/20120820/1345470914)
[RSpecによるユニットテストの書き方](https://recompile.net/posts/how-to-write-unit-test-with-rspec.html)
[改めて学ぶ RSpec](http://magazine.rubyist.net/?0035-RSpecInPractice)
[RSpec の入門とその一歩先へ](http://d.hatena.ne.jp/t-wada/20100228/p1)
[テストコードの期待値はDRYを捨ててベタ書きする ~テストコードの重要な役割とは?~](http://qiita.com/jnchito/items/eb3cfa9f7db752dcb796)
[DRY原則とテストの可読性](http://r7kamura.hatenablog.com/entry/2012/09/02/185129)

laiso

January 19, 2017
Tweet

More Decks by laiso

Other Decks in Technology

Transcript

  1. class PersonTests: XCTestCase { var person: Person! override func setUp()

    { person = Person(name: "John", age: 20) } func testName() { XCTAssertEqual(person.name, "John") } func testAge() { XCTAssertEqual(person.age, 20) } }
  2. class PersonSpec: QuickSpec { override func spec() { var person:

    Person! beforeEach { person = Person(name: "John", age: 20) } it("Name") { XCTAssertEqual(person.name, "John") } it("Age") { XCTAssertEqual(person.age, 20) } } }
  3. class PersonTests: XCTestCase { func testJohn() { let person =

    Person(name: "John", age: 28) XCTAssertEqual(person.name, "John") XCTAssertEqual(person.age, 28) } func testNancy() { let person = Person(name: "Nancy", age: 18) XCTAssertEqual(person.name, "Nancy") XCTAssertEqual(person.age, 18) } }
  4. class PersonSpec: QuickSpec { override func spec() { var person:

    Person! context("John") { beforeEach { person = Person(name: "John", age: 28) } it("Name") { XCTAssertEqual(person.name, "John") } it("Age") { XCTAssertEqual(person.age, 28) } } context("Nancy") { beforeEach { person = Person(name: "Nancy", age: 18) } it("Name") { XCTAssertEqual(person.name, "Nancy") } it("Age") { XCTAssertEqual(person.age, 28) } } } }
  5. class PersonAsJohnTests: XCTestCase { var john: Person! override func setUp()

    { john = Person(name: "John", age: 20) } //func testName() { //func testAge() { } class PersonAsNancyTests: XCTestCase { var nancy: Person! override func setUp() { nancy = Person(name: "Nancy", age: 18) } //func testName() { //func testAge() { }