25. TDD
let interactor = Interactor()
interactor.presenter = MockPresenter()
Verify function is called with parameter message
interactor.presenter.presentError(message)
verify(interactor.presenter.presentError(message))
26. TDD
CREATE MOCK MANUALLY OR WITH TOOL
▸ Tool: Cuckoo
▸ https://github.com/Brightify/Cuckoo
▸ Auto-generate mock objects for Swift Protocol
▸ Simulate stub behaviors on each method
▸ Verify if a method is called with certain parameters
28. TDD
EFFECTIVE TESTS USING XCTEST
▸ Test_MethodName_StateUnderTest_ExpectedBehavior
Naming convention
29. TDD
EFFECTIVE TESTS USING XCTEST
Arrange, Act, and Assert
class BananaTests: XCTestCase {
func testPeel() {
// Arrange: Create the banana we'll be peeling.
let banana = Banana()
// Act: Peel the banana.
banana.peel()
// Assert: Verify that the banana is now edible.
XCTAssertTrue(banana.isEdible)
}
}
30. TDD
STRUCTURE TEST WITH TOOLS
▸ Tool: Quick & Nimble
▸ https://github.com/Quick/Quick
▸ Force developer adding clear comments for each key
section
31. TDD
STRUCTURE TEST WITH TOOLS
▸ Tool: Quick & Nimble
func testDolphin_click_whenTheDolphinIsNearSomethingInteresting_isEmittedThreeTimes() {
// ...
}
describe("a dolphin") {
describe("its click") {
context("when the dolphin is near something interesting") {
it("is emitted three times") {
// ...
}
}
}
}
32. TDD
KEY ELEMENTS IN QUICK
▸ describe closure: Describing Classes and Methods
▸ context closure: Specifying Conditional Behavior
▸ it closure: Assert if requirement is met
describe("a dolphin") {
describe("its click") {
context("when the dolphin is near something interesting") {
it("is emitted three times") {
// verify or assert
}
}
}
}