All Projects → winterbe → Expekt

winterbe / Expekt

Licence: mit
BDD assertion library for Kotlin

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Expekt

Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-74.85%)
Mutual labels:  test, bdd, assertions
Catch Exception
Stars: ✭ 137 (-15.95%)
Mutual labels:  bdd, junit, assertions
Should.js
BDD style assertions for node.js -- test framework agnostic
Stars: ✭ 1,908 (+1070.55%)
Mutual labels:  test, bdd, assertions
Assert
A collection of convenient assertions for Swift testing
Stars: ✭ 69 (-57.67%)
Mutual labels:  test, assertions
Phpspec Code Coverage
Generate Code Coverage reports for PhpSpec tests
Stars: ✭ 59 (-63.8%)
Mutual labels:  bdd, unittest
Pytest Spec
Library pytest-spec is a pytest plugin to display test execution output like a SPECIFICATION.
Stars: ✭ 65 (-60.12%)
Mutual labels:  test, unittest
Grappa
Behavior-oriented, expressive, human-friendly Python assertion library for the 21st century
Stars: ✭ 119 (-26.99%)
Mutual labels:  bdd, assertions
Junitperf
⛵️Junit performance rely on junit5 and jdk8+.(java 性能测试框架)
Stars: ✭ 86 (-47.24%)
Mutual labels:  test, junit
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-23.93%)
Mutual labels:  bdd, assertions
Verify
BDD Assertions for PHPUnit and Codeception
Stars: ✭ 127 (-22.09%)
Mutual labels:  bdd, assertions
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+8474.23%)
Mutual labels:  test, unittest
Kahlan
✔️ PHP Test Framework for Freedom, Truth, and Justice
Stars: ✭ 1,065 (+553.37%)
Mutual labels:  test, bdd
Company Structure
A company structure with a list of projects and their users
Stars: ✭ 48 (-70.55%)
Mutual labels:  junit, unittest
Testify
A unit testing framework written in bash for bash scripts
Stars: ✭ 45 (-72.39%)
Mutual labels:  test, unittest
Postman Bdd
A BDD test framework for Postman and Newman
Stars: ✭ 139 (-14.72%)
Mutual labels:  bdd, assertions
Spek
🎏 Function builder BDD testing framework in Swift
Stars: ✭ 104 (-36.2%)
Mutual labels:  test, bdd
Capture Stream
Capture stream output.
Stars: ✭ 10 (-93.87%)
Mutual labels:  test, unittest
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+459.51%)
Mutual labels:  test, bdd
Scott
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java
Stars: ✭ 125 (-23.31%)
Mutual labels:  junit, assertions
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (-15.34%)
Mutual labels:  test, bdd

Expekt Travic CI

Expekt is a (work in progress) BDD assertion library for Kotlin, inspired by Chai.js. It works with your favorite test runner such as JUnit and Spek.

class ExpektTest {
    @Test
    fun helloExpekt() {
        23.should.equal(23)
        "Kotlin".should.not.contain("Scala")
        listOf(1, 2, 3).should.have.size.above(1)
    }
}

Follow on Twitter for updates!

Getting started

Expekt is available via Maven Central. Just add the dependency to your Maven POM or Gradle build config.

Maven
<dependency>
    <groupId>com.winterbe</groupId>
    <artifactId>expekt</artifactId>
    <version>0.5.0</version>
    <scope>test</scope>
</dependency>
Gradle
testCompile "com.winterbe:expekt:0.5.0"

Introduction

Expekt let's you write assertions in natural english language by building fluent sentences in your JUnit tests.

It comes in two flavors should and expect, both exposing the same API. It's up to you which variant to use. The property should is available on any object (e.g. myObject.should), even on null. The function expect accepts any object as parameter (e.g. expect(myObject)) instead.

When using IntelliJ IDEA you can simply use expect and should from classpath. The IDE handles all imports for you. In case you have to handle imports manually, add one of those to your test file:

import com.winterbe.expekt.expect
import com.winterbe.expekt.should

The Expekt API consists of many chainable properties and functions. Properties like to, be and which are provided to improve readibility. They don't serve any semantical meaning. The property not is used to negate expectations. Depending on the type of the initial value plenty of properties and functions are available to assert different aspects of the value, e.g. you can assert that a collection contains some elements, that a number is within it's bounds or that a string matches a given regex pattern.

See API doc for all available assertion properties and functions.

What happens when expectations fail?

When an expectation fails Expekt throws a java.lang.AssertionError containing a readable message, so you can easily see what's going wrong.

class FailingTest {
    @Test
    fun thisTestFails() {
        3.4.should.be.closeTo(3.2, delta = 0.1)
    }
}

The above test fails, resulting in the following exception:

java.lang.AssertionError: 3.4 should be closeTo 3.2 ±0.1

	at com.winterbe.expekt.ExpectAny.fail(ExpectAny.kt:77)
	at com.winterbe.expekt.ExpectAny.verify(ExpectAny.kt:68)
	at com.winterbe.expekt.ExpectDouble.closeTo(ExpectDouble.kt:12)
	at com.example.ExampleTest.example1(ExampleTest.kt:10)

Examples

Example assertions using the should property:

23.should.equal(23)
null.should.be.`null`
"foo".should.not.equal("bar")
3.should.satisfy { it % 2 == 1 }
3.should.be.above(2).and.below(4)
"abc".should.contain("bc").and.startWith("a")
"abc".should.not.have.length.above(3)
"abc".should.not.match(Regex("[0-9]+"))
listOf(1, 2, 3).should.contain(3).and.have.length.above(2)
listOf(1, 2, 3).should.contain.any.elements(1, 3, 4)
listOf(1, 2, 3).should.have.all.elements(1, 2, 3)
mapOf("foo" to "bar", "bar" to "foo").should.contain("foo" to "bar")

Example assertions using the expect function:

expect(23).to.equal(23)
expect(null).to.be.`null`
expect("foo").not.to.equal("bar")
expect(3).not.to.satisfy { it % 2 == 1 }
expect(3).to.be.above(2).and.to.be.below(4)
expect("abc").to.contain("bc").and.to.startWith("a")
expect("abc").not.to.have.length.above(3)
expect("abc").not.to.match(Regex("[0-9]+"))
expect(listOf(1, 2, 3)).to.contain(3).and.to.have.length.above(2)
expect(listOf(1, 2, 3)).to.contain.any.elements(1, 3, 4)
expect(listOf(1, 2, 3)).to.have.all.elements(1, 2, 3)
expect(mapOf("foo" to "bar", "bar" to "foo")).to.contain("foo" to "bar")

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].