About Quick & Nimble
Quick and Nimble are a pair of testing frameworks for Swift that follow Behavior-Driven Development (BDD) principles. Quick provides a structure for writing descriptive tests, while Nimble offers powerful matching patterns that make assertions more readable.
Key Features
- BDD-style syntax
- Nested test organization
- Expressive matchers
- Asynchronous testing
- Custom failure messages
Code Example
// Quick & Nimble example
import Quick
import Nimble
@testable import MyApp
class UserViewModelSpec: QuickSpec {
override func spec() {
describe("UserViewModel") {
var viewModel: UserViewModel!
beforeEach {
viewModel = UserViewModel()
}
context("when initialized with default values") {
it("has empty username") {
expect(viewModel.username).to(beEmpty())
}
it("is not authenticated") {
expect(viewModel.isAuthenticated).to(beFalse())
}
}
context("when logging in") {
beforeEach {
viewModel.username = "testuser"
viewModel.password = "password123"
}
it("authenticates with valid credentials") {
viewModel.login()
expect(viewModel.isAuthenticated).toEventually(beTrue())
expect(viewModel.error).to(beNil())
}
it("shows error with invalid credentials") {
viewModel.password = "wrong"
viewModel.login()
expect(viewModel.isAuthenticated).to(beFalse())
expect(viewModel.error).toEventuallyNot(beNil())
}
}
context("when formatting display name") {
it("capitalizes first letters") {
viewModel.firstName = "john"
viewModel.lastName = "doe"
expect(viewModel.displayName).to(equal("John Doe"))
}
it("handles empty strings") {
viewModel.firstName = ""
viewModel.lastName = ""
expect(viewModel.displayName).to(equal(""))
}
}
}
}
}