Top Related Projects
Provides a readable API to express expected outcomes of a code example
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Simple JavaScript testing framework for browsers and node.js
Additional Jest matchers 🃏💪
BDD style assertions for node.js -- test framework agnostic
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Quick Overview
Quick/Nimble is a popular testing framework for Swift and Objective-C, designed to make writing expressive and readable tests easier. It provides a set of matchers and a fluent syntax that allows developers to write tests that closely resemble natural language, improving code clarity and maintainability.
Pros
- Expressive and readable syntax that closely resembles natural language
- Extensive set of built-in matchers for various testing scenarios
- Seamless integration with both Swift and Objective-C projects
- Active community and regular updates
Cons
- Steeper learning curve compared to XCTest for developers new to BDD-style testing
- May introduce additional complexity in simpler projects where XCTest suffices
- Requires additional setup and configuration compared to the built-in XCTest framework
Code Examples
- Basic expectation:
expect(2 + 2).to(equal(4))
This example demonstrates a simple expectation that checks if 2 + 2 equals 4.
- Asynchronous testing:
waitUntil { done in
performAsyncTask { result in
expect(result).to(beSuccessful())
done()
}
}
This example shows how to test asynchronous code using the waitUntil
function.
- Custom matcher:
func beEven() -> Predicate<Int> {
return Predicate { expression in
guard let number = try expression.evaluate() else {
return PredicateResult(status: .fail, message: .fails("Unable to evaluate expression"))
}
return PredicateResult(bool: number % 2 == 0, message: .expectedCustomValueTo("be even", actual: "\(number)"))
}
}
expect(4).to(beEven())
This example demonstrates how to create a custom matcher to check if a number is even.
Getting Started
To use Quick/Nimble in your Swift project:
- Add the following to your
Package.swift
file:
dependencies: [
.package(url: "https://github.com/Quick/Quick.git", from: "5.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "10.0.0")
]
- Import Quick and Nimble in your test file:
import Quick
import Nimble
class MySpec: QuickSpec {
override func spec() {
describe("MyClass") {
it("should perform a specific action") {
let result = MyClass().someMethod()
expect(result).to(equal(expectedValue))
}
}
}
}
This setup allows you to start writing tests using Quick and Nimble in your Swift project.
Competitor Comparisons
Provides a readable API to express expected outcomes of a code example
Pros of rspec-expectations
- Mature and widely adopted in the Ruby ecosystem
- Extensive documentation and community support
- Rich set of built-in matchers for various scenarios
Cons of rspec-expectations
- Limited to Ruby language and ecosystem
- Syntax can be verbose for complex expectations
- Learning curve for newcomers to Ruby testing
Code Comparison
rspec-expectations:
expect(result).to eq(42)
expect(array).to include(3)
expect { action }.to change { object.value }.from(1).to(2)
Nimble:
expect(result).to(equal(42))
expect(array).to(contain(3))
expect { action() }.to(change { object.value }.from(1).to(2))
Key Differences
- Language: rspec-expectations is for Ruby, while Nimble is for Swift
- Ecosystem: rspec-expectations is part of the larger RSpec framework, Nimble is often used with Quick
- Syntax: Nimble's syntax is slightly more concise and Swift-friendly
- Matchers: Both offer a wide range of matchers, but rspec-expectations has a larger built-in set
- Community: rspec-expectations has a larger community due to its longer history in the Ruby world
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Pros of Mocha
- Widely adopted in the JavaScript ecosystem with extensive community support
- Flexible and compatible with various assertion libraries and test runners
- Supports both synchronous and asynchronous testing out of the box
Cons of Mocha
- Requires additional setup for assertion libraries and mocking frameworks
- Can be slower for large test suites compared to more lightweight alternatives
- Less opinionated, which may lead to inconsistent testing practices across projects
Code Comparison
Mocha:
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal([1, 2, 3].indexOf(4), -1);
});
});
});
Nimble:
describe("Array") {
describe("indexOf()") {
it("should return -1 when the value is not present") {
expect([1, 2, 3].indexOf(4)).to(equal(-1))
}
}
}
Both frameworks use a similar describe-it structure for organizing tests, but Nimble (part of Quick) provides a more expressive syntax for assertions with its expect
function and matchers. Mocha, being JavaScript-based, is more versatile across different JavaScript environments, while Nimble is specifically designed for Swift testing.
Simple JavaScript testing framework for browsers and node.js
Pros of Jasmine
- Wider language support: Works with JavaScript, TypeScript, and various frameworks
- Simpler setup: No additional dependencies required for basic testing
- Extensive documentation and large community support
Cons of Jasmine
- Less expressive syntax compared to Nimble's matcher-based approach
- Slower test execution, especially for large test suites
- Limited built-in asynchronous testing capabilities
Code Comparison
Jasmine:
describe("Calculator", function() {
it("should add two numbers", function() {
expect(add(2, 3)).toBe(5);
});
});
Nimble:
describe("Calculator") {
it("should add two numbers") {
expect(add(2, 3)).to(equal(5))
}
}
Key Differences
- Syntax: Nimble uses a more expressive, chainable syntax for assertions
- Language: Jasmine is primarily for JavaScript, while Nimble is for Swift
- Matchers: Nimble offers a wider range of built-in matchers and easier custom matcher creation
- Asynchronous testing: Nimble provides more robust support for async testing out of the box
- Performance: Nimble generally offers faster test execution, especially for larger test suites
Both frameworks are popular choices in their respective ecosystems, with Jasmine being more established in the JavaScript world and Nimble gaining traction in the Swift community.
Additional Jest matchers 🃏💪
Pros of jest-extended
- Extends Jest's built-in matchers, providing a wider range of assertion options
- Seamlessly integrates with existing Jest setups, requiring minimal configuration
- Actively maintained with regular updates and community contributions
Cons of jest-extended
- Limited to JavaScript/TypeScript ecosystems, unlike Nimble's Swift support
- May introduce additional complexity for simple test cases
- Requires Jest as a dependency, which might not be suitable for all projects
Code Comparison
jest-extended:
expect(array).toBeArrayOfSize(3);
expect(value).toBeWithin(start, end);
expect(func).toThrowWithMessage(Error, 'Error message');
Nimble:
expect(array).to(haveCount(3))
expect(value).to(beCloseTo(5, within: 0.01))
expect { expression }.to(throwError { (error: Error) in
expect(error.localizedDescription).to(equal("Error message"))
})
Both libraries extend the capabilities of their respective testing frameworks, providing more expressive and readable assertions. jest-extended focuses on enhancing Jest for JavaScript/TypeScript, while Nimble is tailored for Swift development. The syntax differs due to language differences, but both aim to improve test readability and reduce boilerplate code.
BDD style assertions for node.js -- test framework agnostic
Pros of should.js
- More extensive and flexible assertion syntax
- Supports both Node.js and browser environments
- Large community and ecosystem with numerous plugins
Cons of should.js
- Slower performance compared to Nimble
- Larger library size, which may impact load times
- Less integrated with Swift and iOS development
Code Comparison
should.js:
[1, 2, 3].should.have.length(3);
user.should.have.property('name', 'John');
promise.should.be.fulfilled();
Nimble:
expect([1, 2, 3]).to(haveCount(3))
expect(user.name).to(equal("John"))
expect(promise).to(beSuccessful())
Summary
should.js is a versatile assertion library for JavaScript, offering a wide range of assertion methods and compatibility with various environments. It has a larger community and more extensive documentation. However, it may have performance drawbacks and a larger footprint compared to Nimble.
Nimble, on the other hand, is tailored for Swift and iOS development, providing a more streamlined and performant solution for those ecosystems. It offers a clean syntax that integrates well with Swift's language features but may have a smaller set of assertion methods compared to should.js.
The choice between the two depends on the development environment, language preferences, and specific project requirements.
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Pros of Chai
- More extensive and flexible assertion library with multiple styles (expect, should, assert)
- Broader ecosystem with plugins and extensions
- Supports both Node.js and browser environments
Cons of Chai
- Steeper learning curve due to multiple assertion styles
- Larger bundle size, which may impact performance in browser environments
- Less integrated with testing frameworks compared to Nimble's tight coupling with Quick
Code Comparison
Chai:
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
Nimble:
expect(foo).to(beAKindOf(String.self))
expect(foo).to(equal("bar"))
expect(foo).to(haveCount(3))
Summary
Chai is a versatile assertion library for JavaScript, offering multiple styles and broad ecosystem support. Nimble, tailored for Swift, provides a more focused and integrated experience with the Quick testing framework. While Chai offers flexibility across environments, Nimble excels in Swift-specific testing scenarios with a more streamlined API.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Nimble
Use Nimble to express the expected outcomes of Swift or Objective-C expressions. Inspired by Cedar.
// Swift
expect(1 + 1).to(equal(2))
expect(1.2).to(beCloseTo(1.1, within: 0.1))
expect(3) > 2
expect("seahorse").to(contain("sea"))
expect(["Atlantic", "Pacific"]).toNot(contain("Mississippi"))
expect(ocean.isClean).toEventually(beTruthy())
Documentation
Nimble's documentation is now lives in Sources/Nimble/Nimble.docc as a Documentation Catalog. You can easily browse it quick.github.io/Nimble.
Installing Nimble
Nimble can be used on its own, or in conjunction with its sister project, Quick. To install both Quick and Nimble, follow the installation instructions in the Quick Documentation.
Nimble can currently be installed in one of four ways: Swift Package Manager, CocoaPods, Carthage or with git submodules.
Swift Package Manager
Xcode
To install Nimble via Xcode's Swift Package Manager Integration:
Select your project configuration, then the project tab, then the Package
Dependencies tab. Click on the "plus" button at the bottom of the list,
then follow the wizard to add Quick to your project. Specify
https://github.com/Quick/Nimble.git
as the url, and be sure to add
Nimble as a dependency of your unit test target, not your app target.
Package.Swift
To use Nimble with Swift Package Manager to test your applications, add Nimble
to your Package.Swift
and link it with your test target:
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "MyAwesomeLibrary",
products: [
// ...
],
dependencies: [
// ...
.package(url: "https://github.com/Quick/Nimble.git", from: "13.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "MyAwesomeLibrary",
dependencies: ...),
.testTarget(
name: "MyAwesomeLibraryTests",
dependencies: ["MyAwesomeLibrary", "Nimble"]),
]
)
Please note that if you install Nimble using Swift Package Manager, then raiseException
is not available.
CocoaPods
To use Nimble in CocoaPods to test your macOS, iOS, tvOS or watchOS applications, add
Nimble to your podfile and add the use_frameworks!
line to enable Swift
support for CocoaPods.
platform :ios, '13.0'
source 'https://github.com/CocoaPods/Specs.git'
# Whatever pods you need for your app go here
target 'YOUR_APP_NAME_HERE_Tests', :exclusive => true do
use_frameworks!
pod 'Nimble'
end
Finally run pod install
.
Carthage
To use Nimble in Carthage to test your macOS, iOS, tvOS or watchOS applications,
add Nimble to your Cartfile.private
:
github "Quick/Nimble" ~> 13.2
Then follow the rest of the Carthage Quick Start and link Nimble with your unit tests.
Git Submodules
To use Nimble as a submodule to test your macOS, iOS or tvOS applications, follow these 4 easy steps:
- Clone the Nimble repository
- Add Nimble.xcodeproj to the Xcode workspace for your project
- Link Nimble.framework to your test target
- Start writing expectations!
For more detailed instructions on each of these steps, read How to Install Quick. Ignore the steps involving adding Quick to your project in order to install just Nimble.
Privacy Statement
Nimble is a library that is only used for testing and should never be included in the binary submitted to App Store Connect.
Despite not being shipped to Apple, Nimble does not and will never collect any kind of analytics or tracking.
Top Related Projects
Provides a readable API to express expected outcomes of a code example
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Simple JavaScript testing framework for browsers and node.js
Additional Jest matchers 🃏💪
BDD style assertions for node.js -- test framework agnostic
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot