Code Monkey home page Code Monkey logo

kotlintest's Introduction

KotlinTest

Join the chat at https://gitter.im/kotlintest/lobby Build Status Build status GitHub license

KotlinTest is a flexible and comprehensive testing tool for Kotlin.
Full documentation

For latest updates see Changelog

Community

Test with Style

Write simple and beautiful tests with the StringSpec style:

class MyTests : StringSpec({
  "length should return size of string" {
    "hello".length shouldBe 5
  }
  "startsWith should test for a prefix" {
    "world" should startWith("wor")
  }
})

You can choose the testing style that fits your needs.

Multitude of Matchers

Use over 100 provided matchers to test assertions on many different types:

"substring" should include("str")

user.email should beLowerCase()

myImmgeFile should haveExtension(".jpg")

cityMap should haveKey("London")

See the full list of matchers or write your own.

Let the Computer Generate Your Test Data

Use property based testing to test your code with automatically generated test data:

class PropertyExample: StringSpec() {
  init {
    "String size" {
      assertAll { a: String, b: String ->
        (a + b) should haveLength(a.length + b.length)
      }
    }
}

Check all the Tricky Cases With Table Testing

Handle even an enormous amount of input parameter combinations easily with table driven tests:

class StringSpecExample : StringSpec() {
  init {

    "should add" {
       val myTable = table(
         headers("a", "b", "result"),
         row(1, 2, 3),
         row(1, 1, 2)
       )
       forAll(myTable) { a, b, result ->
         a + b shouldBe result
       }
    }

  }
}

Test Exceptions

Testing for exceptions is easy with KotlinTest:

val exception = shouldThrow<IllegalAccessException> {
  // code in here that you expect to throw an IllegalAccessException
}
exception.message should startWith("Something went wrong")

Fine Tune Test Execution

You can specify the number of threads, invocations, and a timeout for each test or for all tests. And you can group tests by tags or disable them conditionally. All you need is config:

class MySpec : StringSpec() {

  override val defaultTestCaseConfig = TestCaseConfig(invocations = 3)

  init {
    "should use config" {
      // ...
    }.config(timeout = 2.seconds, invocations = 10, threads = 2, tags = setOf(Database, Linux))
  }
}

And More ...

This page gives you just a short overview over KotlinTest. There are some more useful things:

See full documentation.

Use

Gradle:

buildscript {
    dependencies {
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.1.0"
    }
}
// This allows gradle to execute _jUnit-platform-5_ based tests (which KotlinTest builds upon). 
// Note: Gradle says that this is **not** required as of 4.6 but even with 4.6 it seems to be required.
apply plugin: 'org.junit.platform.gradle.plugin'

testCompile 'io.kotlintest:kotlintest-runner-junit5:3.0.4'

Maven:

<dependency>
    <groupId>io.kotlintest</groupId>
    <artifactId>kotlintest-runner-junit5</artifactId>
    <version>3.0.4</version>
    <scope>test</scope>
</dependency>

kotlintest's People

Contributors

sksamuel avatar helmbold avatar sschuberth avatar reckter avatar andrzejressel avatar leocolman avatar sandwwraith avatar benjamin-bader avatar vkolomeyko avatar mfriedenhagen avatar hastebrot avatar clemp6r avatar michaelrocks avatar elect86 avatar oripwk avatar pakoito avatar roschlau avatar ruslanas avatar seanfisk avatar superbobry avatar sergiords avatar leisim avatar tgirard12 avatar meoyawn avatar bondpp7 avatar memoizr avatar neyb avatar stormcat24 avatar ykrasik avatar xenomachina avatar

Watchers

James Cloos avatar Tiago Domingos 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.