Who we are
• Mobile team at railsware.com
• Open source fans railsware.github.io/
Slide 3
Slide 3 text
Outline
• What is BDD
• Testing in Swift - XCTest vs BDD style
• What Sleipnir is
• How to use it
• Questions
Slide 4
Slide 4 text
BDD
Slide 5
Slide 5 text
BDD
Behavior Driven Development
Slide 6
Slide 6 text
BDD
Behavior Driven Development
• BDD specifies that tests of any unit of software should be
specified in terms of the desired behaviour of the unit.
(from Wiki)
!
• BDD is all about specifications
Slide 7
Slide 7 text
BDD
describe("Calculator") {
!
describe("#add") {
!
it("returns the sum of its arguments") {
expect(Calculator().add(1, 2)).to(equal(3))
}
}
}
Slide 8
Slide 8 text
Testing in Swift
Slide 9
Slide 9 text
Testing in Swift - XCTest
class BookTest : XCTestCase {
func testPersonHasName() {
let person = Person(name: "John Doe”)
!
XCTAssertNotNil(person.name, "name should not be nil")
XCTAssertEqual(person.name, "John Doe", "incorrect name")
}
}
Slide 10
Slide 10 text
Testing in Swift - XCTest
class BookTest : XCTestCase {
func testPersonHasName() {
let person = Person(name: "John Doe”)
!
XCTAssertNotNil(person.name, "name should not be nil")
XCTAssertEqual(person.name, "John Doe", "incorrect name")
}
}
Does not specify behavior of the `Person` class
Slide 11
Slide 11 text
Testing in Swift - BDD
class PersonSpec : SleipnirSpec {
var personSpec = describe("Person") {
let person = Person(name: "John Doe")
context("name") {
it("should not be nil") {
expect(person.name).toNot(beNil())
}
it("should be correct") {
expect(person.name).to(equal("John Doe"))
}
}
}
}
Slide 12
Slide 12 text
Testing in Swift - BDD
Test code is a specification of a class:
• Person name should not be nil
• Person name should be correct
Pending specs
Pending means “Don’t run this stuff”
Useful to denote an example that does not pass yet
Slide 27
Slide 27 text
Pending specs
xdescribe("Pending group") {
it("will not run") {
expect(false).to(beTrue())
}
it("is pending", PENDING)
}
Running With Random Seed: 2428
!
...P.......
!
PENDING Pending group is pending
!
!
Finished in 0.0062 seconds
!
11 examples, 0 failures, 1 pending
Slide 28
Slide 28 text
Shared example groups
Useful for extracting common specs
Allow to run same specs in different context
Slide 29
Slide 29 text
Shared example groups
sharedExamplesFor("some awesome stuff") {
(sharedContext : SharedContext) in
var stuff: Stuff?
beforeEach {
stuff = sharedContext()["stuff"] as Stuff
}
it("should be awesome") {
expect(stuff.awesome).to(beTrue())
}
}