SlideShare a Scribd company logo
Sleipnir
BDD style testing for Swift
Who we are
• Mobile team at railsware.com
• Open source fans railsware.github.io/
Outline
• What is BDD
• Testing in Swift - XCTest vs BDD style
• What Sleipnir is
• How to use it
• Questions
BDD
BDD
Behavior Driven Development
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
BDD
describe("Calculator") {
!
describe("#add") {
!
it("returns the sum of its arguments") {
expect(Calculator().add(1, 2)).to(equal(3))
}
}
}
Testing in Swift
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")
}
}
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
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"))
}
}
}
}
Testing in Swift - BDD
Test code is a specification of a class:
• Person name should not be nil
• Person name should be correct
Introducing Sleipnir
https://github.com/railsware/Sleipnir
What Sleipnir is
Mythological steed of Odin, Norse God
What Sleipnir is
BDD-style framework for Swift
What Sleipnir is
class HorseSpec : SleipnirSpec {
var spec = describe("Horse") {
context("usual") {
it("is not awesome") {
let usualHorse = UsualHorse()
expect(usualHorse.legsCount).to(equal(4))
usualHorse.isAwesome.should.beFalse()
}
}
context("Sleipnir") {
it("is awesome") {
let sleipnirHorse = Sleipnir()
expect(sleipnirHorse.legsCount).to(equal(8))
sleipnirHorse.isAwesome.should.beTrue()
}
}
}
}
Core principles
• Not using XCTest
• Pure Swift BDD testing framework
• Command line output
• Seeded random tests invocation
How to use it
Running specs
1. Create a test target in Xcode
2. Invoke Runner.run() method in main.swift
3. Run test target
Running specs
Running With Random Seed: 7197
!
...F......
!
!
FAILURE Some spec should pass:
/Path/To/Your/Specs/SomeSpec.swift:27 Expected <1> to equal <3>
!
!
Finished in 0.0102 seconds
!
10 examples, 1 failures
Setup/Teardown blocks
• beforeEach { }
• afterEach { }
• beforeAll { }
• afterAll { }
Setup/Teardown blocks
let someSpec = describe("Some spec") {
var someArray: [Int]?
!
beforeEach {
someArray = [1, 2, 3]
}
afterEach {
someArray = nil
}
it("should pass") {
expect(someArray).toNot(beNil())
expect(someArray).to(contain(3))
}
}
Focused specs
Focus means “Run only focused stuff”
Useful in a project with a lot of specs
Focused specs
describe("Some spec") {
fit("focused") {
// WILL RUN
}
it("not focused") {
// WILL NOT RUN
}
}
Focused specs
fdescribe("focused group") {
// ...
}
!
fcontext("focused group") {
// ...
}
fit("focused example") {
// ...
}
Pending specs
Pending means “Don’t run this stuff”
Useful to denote an example that does not pass yet
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
Shared example groups
Useful for extracting common specs
Allow to run same specs in different context
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())
}
}
Matchers
• equal
• beNil
• beFalse/beTrue
• beGreaterThan/beLessThan
expect(3).to(equal(3))
expect(3).toNot(beNil())
expect(true).to(beTrue())
expect(3).to(beGreaterThan(1))
Matchers on collections/strings
• contain
• beginWith/endWith
• beEmpty
expect([1,2,3]).to(contain(1,2))
expect("foobar").to(beginWith("foo"))
expect([1,2,3]).toNot(beEmpty())
Questions?
https://github.com/railsware/Sleipnir

More Related Content

PDF
Survive JavaScript - Strategies and Tricks
PDF
Testing with Express, Mocha & Chai
PPTX
Racing car katas Ⅲ - Static Cling
PPTX
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
PDF
BarcelonaJUG2016: walkmod: how to run and design code transformations
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
PDF
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
PDF
Solid And Sustainable Development in Scala
Survive JavaScript - Strategies and Tricks
Testing with Express, Mocha & Chai
Racing car katas Ⅲ - Static Cling
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
BarcelonaJUG2016: walkmod: how to run and design code transformations
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
Solid And Sustainable Development in Scala

What's hot (20)

PDF
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
PDF
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
PDF
Introduction to Kotlin JVM language
PDF
データーベースとインデックス
PDF
walkmod: how it works
PDF
Developing Useful APIs
PDF
PDF
Just Do It! ColdBox Integration Testing
KEY
Objective C 基本介紹
PDF
Lagergren jvmls-2013-final
PDF
Observing Change: A Gold Master Test in Practice
PDF
TypeProf for IDE: Enrich Development Experience without Annotations
PPTX
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
PDF
Enjoy Ruby Programming in IDE and TypeProf
PDF
Cookpad Hackarade #04: Create Your Own Interpreter
PDF
Mocha, chai and sinon
PPTX
25csharp
PDF
A Taste of Clojure
PDF
Swift and Kotlin Presentation
PDF
A new execution model for Nashorn in Java 9
«Как сделать так, чтобы тесты на Swift не причиняли боль» Сычев Александр, Ra...
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
Introduction to Kotlin JVM language
データーベースとインデックス
walkmod: how it works
Developing Useful APIs
Just Do It! ColdBox Integration Testing
Objective C 基本介紹
Lagergren jvmls-2013-final
Observing Change: A Gold Master Test in Practice
TypeProf for IDE: Enrich Development Experience without Annotations
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Enjoy Ruby Programming in IDE and TypeProf
Cookpad Hackarade #04: Create Your Own Interpreter
Mocha, chai and sinon
25csharp
A Taste of Clojure
Swift and Kotlin Presentation
A new execution model for Nashorn in Java 9
Ad

Viewers also liked (6)

PPTX
Pedalim vacancy IT HR
DOC
StanCV1[1][1].dcc (1)
DOCX
VALERIY MALY
DOCX
Vladyslav_Chapiuk_Resume_en
PDF
Roman Myronov CV
PPTX
Результаты педагогов и учащихся школ Москвы в 2015-2016 учебном году
Pedalim vacancy IT HR
StanCV1[1][1].dcc (1)
VALERIY MALY
Vladyslav_Chapiuk_Resume_en
Roman Myronov CV
Результаты педагогов и учащихся школ Москвы в 2015-2016 учебном году
Ad

Similar to Sleipnir presentation (20)

PDF
Quick tour to front end unit testing using jasmine
PDF
Swift Micro-services and AWS Technologies
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
PPTX
Zero to Testing in JavaScript
PDF
Triton and symbolic execution on gdb
PDF
SquiDB: a SQLite layer for Android - Jonathan Koren, Yahoo!
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PPTX
JS Frameworks Day April,26 of 2014
PDF
Js fwdays unit tesing javascript(by Anna Khabibullina)
PDF
10 Techniques to writing easy yet stupidly thorough unit tests.pdf
PDF
CBDW2014 - Behavior Driven Development with TestBox
PPTX
Triton and Symbolic execution on GDB@DEF CON China
PDF
Angular Application Testing
PDF
It's all about behaviour, also in php - phpspec
PPTX
Testing in Scala. Adform Research
PPTX
Testing in Scala by Adform research
PDF
Terence Barr - jdk7+8 - 24mai2011
PDF
20140406 loa days-tdd-with_puppet_tutorial
PDF
Solid and Sustainable Development in Scala
Quick tour to front end unit testing using jasmine
Swift Micro-services and AWS Technologies
Rspec and Capybara Intro Tutorial at RailsConf 2013
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Zero to Testing in JavaScript
Triton and symbolic execution on gdb
SquiDB: a SQLite layer for Android - Jonathan Koren, Yahoo!
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
JS Frameworks Day April,26 of 2014
Js fwdays unit tesing javascript(by Anna Khabibullina)
10 Techniques to writing easy yet stupidly thorough unit tests.pdf
CBDW2014 - Behavior Driven Development with TestBox
Triton and Symbolic execution on GDB@DEF CON China
Angular Application Testing
It's all about behaviour, also in php - phpspec
Testing in Scala. Adform Research
Testing in Scala by Adform research
Terence Barr - jdk7+8 - 24mai2011
20140406 loa days-tdd-with_puppet_tutorial
Solid and Sustainable Development in Scala

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Lecture Notes Electrical Wiring System Components
DOCX
573137875-Attendance-Management-System-original
PPTX
additive manufacturing of ss316l using mig welding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
PPT on Performance Review to get promotions
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Well-logging-methods_new................
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Sustainable Sites - Green Building Construction
PPT
Project quality management in manufacturing
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
CH1 Production IntroductoryConcepts.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Lecture Notes Electrical Wiring System Components
573137875-Attendance-Management-System-original
additive manufacturing of ss316l using mig welding
Model Code of Practice - Construction Work - 21102022 .pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT on Performance Review to get promotions
Operating System & Kernel Study Guide-1 - converted.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Well-logging-methods_new................
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Sustainable Sites - Green Building Construction
Project quality management in manufacturing

Sleipnir presentation