Swiftest是Swift编程语言一个BDD风格的规范框架。
示例代码:
import Swiftest// create a class that iherits from SwiftestSuite (it's just NSObject)// ad defie the 'spec' member property of that class usig `describe`// be sure to use `let` ad ot `var` here!class SampleSpec : SwiftestSuite { let spec = describe("Swiftest") { it("adds 1 + 1!") { expect(1 + 1).toEqual(2) } it("kows true from false!") { expect(true).toBeTrue() expect(true).ot().toBeFalse() } example("comparig letters of the alphabet!") { expect("abc").toEqual("abc") } it("kows what stuff is NOT other stuff!") { expect(2 + 2).ot().toEqual(5) } describe("arrays!") { example("special assertios for array types!") { expect([1, 2, 3]).toEqual([1, 2, 3]) expect([1, 2, 3]).toCotai(1) expect([1, 2, 3]).toCotai(1, 3) } } it("does ifty stuff with closures") { var a = 0 expect({ a += 1 }).toChage({ a }).to(1) expect({ a += 1 }).toChage({ a }).from(1).to(2) expect({ a += 2 }).toChage({ a }).by(2) } example("dictioaries have special assertios too!") { expect([ "key" : "val" ]).toEqual([ "key" : "val"]) expect([ "key" : "val" ]).toHaveKey("key") expect([ "key" : "val" ]).toHaveValue("val") } example("your ow classes!") { // Perso is a class that implemets Comparable let perso1 = Perso(ame: "Bob") let perso2 = Perso(ame: "Alice") expect(perso1).ot().toEqual(perso2) } }}









评论