Skip to content
forked from kotest/kotest

Kotlin test framework based on the excellent Scalatest

License

Notifications You must be signed in to change notification settings

sliya/kotlintest

 
 

Repository files navigation

KotlinTest

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

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

For latest updates see Changelog

Community

How to use

For latest updates see Changelog.

Test with Style

Write simple and beautiful tests with the StringSpec style:

class MyTests : StringSpec() {
  init {

    "length should return size of string" {
      "hello".length shouldBe 5
    }

  }
}

You can choose the testing style that fits your needs.

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" {
      forAll { a: String, b: String ->
        (a + b).length == 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:

testCompile 'io.kotlintest:kotlintest:xxx'

Maven:

<dependency>
    <groupId>io.kotlintest</groupId>
    <artifactId>kotlintest</artifactId>
    <version>xxx</version>
    <scope>test</scope>
</dependency>

About

Kotlin test framework based on the excellent Scalatest

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%