Code Monkey home page Code Monkey logo

kwik's Introduction

kwik

License Apache%202.0 blue status incubating orange Build Status download

Property-based testing library for Kotlin.

Main features
  • Test-engine agnostic (Mix property-based tests with example-based tests written for the engine of your choice)

  • Multiplatform

  • No reflection (better compile-time feedback and faster runtime)

  • Configurable built-in generators

  • Easy way to create and combine generators

Have a look at the documentation

Status

The project is incubating and its API may change in the future.

Please give it a try and give feed back in the issues.

Usage

Example with Junit or equivalent
class PlusOperatorTest {

    // Default config and generators
    @Test
    fun isCommutative() = forAll { x: Int, y: Int ->
        x + y == y + x
    }

    // With a given number of iterations
    @Test
    fun isAssociative() = forAll(iterations = 1000) { x: Int, y: Int, z: Int ->
        (x + y) + z == x + (y + z)
    }

    // Use a seed to get reproducible results (useful when investigating a failure in the CI for instance)
    @Test
    fun zeroIsNeutral() = forAll(seed = -4567) { x: Int ->
        x + 0 == x
    }

    // Configure or use a custom generator
    @Test
    fun addNegativeSubtracts() = forAll(Generator.ints(min = 0), Generator.ints(max = 0)) { x, y ->
        x + y <= x
    }

    // Create a custom generator
    val customGenerator1 = Generator.create { rng -> CustomClass(rng.nextInt(), rng.nextInt()) }

    // Combine generators
    val customGenerator2 = Generator.ints().zip(Generator.ints()) { x, y -> CustomClass(x, y) }
}

Motivation

Property based testing is great and very powerful. But despite the fact that many good libraries already exist, none of them fully fit my needs.

The existing alernatives often:
  • Are bound to a specific test-engine

  • Can only be used in Java module (not in Koltin multiplatform modules)

  • Relies on reflection, making them slower then it could be and make some error detectable only at runtime

  • Some of them also force the user to add unwanted dependencies in his/her classpath

Installation

download
  1. Add https://dl.bintray.com/kwik/preview to your maven repositories

  2. Add com.github.jcornaz.kwik:kwik-core-jvm:<version> as a dependency (replacing jvm by common in case of a common module, and replacing <version> by the latest version (see above))

Example with Gradle (Kotlin DSL)
repositories {
    maven { url = uri("https://dl.bintray.com/kwik/preview") }
}

dependencies {

    // in a JVM module
    testCompile("com.github.jcornaz.kwik:kwik-core-jvm:<version>")

    // in a common (multiplatform) module
    testCompile("com.github.jcornaz.kwik:kwik-core-common:<version>")
}

kwik's People

Contributors

jcornaz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.