Skip to content

Latest commit

 

History

History
236 lines (161 loc) · 5.94 KB

CHANGELOG.md

File metadata and controls

236 lines (161 loc) · 5.94 KB

Changelog

This project follows semantic versioning.

Version 2.0.0, released 2017-03-26

Closed Issues

Added

  • You can write tests alternatively into a lambda parameter in the class constructor, eg:
class StringSpecExample : StringSpec({
  "strings.size should return size of string" {
    "hello".length shouldBe 5
    "hello" should haveLength(5)
  }
})
  • Added forNone for table tests, eg
val table = table(
    headers("a", "b"),
    row(0L, 2L),
    row(2L, 2L),
    row(4L, 5L),
    row(4L, 6L)
)

forNone(table) { a, b ->
  3 shouldBe between(a, b)
}
  • Interceptors have been added. Interceptors allow code to be executed before and after a test. See the main readme for more info.

  • Simplified ability to add custom matchers. Simple implement Matcher<T> interface. See readme for more information.

  • Added shouldNot to invert matchers. Eg, "hello" shouldNot include("hallo")

  • Deprecated matchers which do not implement Matcher. Eg, should have substring(x) has been deprecated in favour of "hello" should include("l"). This is because instances of Matcher can be combined with or and and and can be negated with shouldNot.

  • Added between matcher for int and long, eg

3 shouldBe between(2, 5)

  • Added singleElement matcher for collections, eg

x shouldBe singleElement(y)

  • Added sorted matcher for collections, eg

listOf(1,2,3) shouldBe sorted<Int>()

  • Now supports comparsion of arrays #116

  • Added Gen.oneOf to create a generator that returns one of the values for the given Enum class.

Changed

  • Tags are objects derived from Tag class now.
  • Tags can now be included and/or exluded. It is no longer the case that all untagged tests are always executed.
  • Fixed bugs with parenthesis breaking layout in Intellij #112

Removed

  • FlatSpec was removed because it has an irregular syntax with config and is essentially the same as StringSpec, but more complicated.
  • Deprecated method overloads with duration: Long, unit: TimeUnit
  • expecting for testing exceptions (use shouldThrow now)

Version 1.3.2, released 2016-07-05

Changed

  • Added a shouldBe exactly(b) matcher for doubles

  • kotlintest only pulls in mockito-core now instead of mockito-all

Version 1.3.1, released 2016-07-03

Changed

  • Bumped Kotlin version to 1.0.3

Version 1.3.0, released 2016-07-03

Closed Issues

Added

  • StringSpec. You can use simply use Strings as the basis for tests, eg:
class StringSpecExample : StringSpec() {
  init {
    "strings.size should return size of string" {
      "hello".length shouldBe 5
      "hello" should haveLength(5)
    }

    "strings should support config" {
      "hello".length shouldBe 5
    }.config(invocations = 5)
  }
}
  • Table Tests. Tables allow you to manually specific combinations of values that should be used, and are useful for edge cases and other specific values you want to test. The headers are used for when values fail, the output can show you what inputs were used for what labels. An example of using a table consisting of two-value tuples:
class TableExample : StringSpec(), TableTesting {
  init {
    "numbers should be prime" {
      val table = table(
          headers("a", "b"),
          row(5, 5),
          row(4, 6),
          row(3, 7)
      )
      forAll(table) { a, b ->
        a + b == 10
      }
    }
  }
}
  • Property tests. Property tests automatically generate values for testings. You provide, or have KotlinTest provide for you, generators, which will generate a set of values and the unit test will be executed for each of those values. An example using two strings and asserting that the lengths are correct:
class PropertyExample: StringSpec() {

  "String size" {
    forAll({ a: String, b: String ->
      (a + b).length == a.length + b.length
    })
  }

}

That test will be executed 100 times with random values in each test. See more in the readme.

  • autoClose. Fields of type Closeable can be registered for automatic resource closing:
class StringSpecExample : StringSpec() {
  val reader = autoClose(StringReader("xyz"))
  
  ...
}
  • haveLength matcher. You can now write for strings:
someString should haveLength(10)
  • haveSize matcher. You can now write for collections:
myCollection should haveSize(4)
  • contain matcher. You can now write
val col = listOf(1,2,3,4,5)
col should contain(4)
  • containInAnyOrder matcher. You can now write
val col = listOf(1,2,3,4,5)
col should containInAnyOrder(4,2,3)
  • haveKey Map<K,V> matcher. You can now write
val map = mapOf(Pair(1, "a"), Pair(2, "b"))
map should haveKey(1)
  • haveValue Map<K,V> matcher. You can now write
val map = mapOf(Pair(1, "a"), Pair(2, "b"))
map should haveValue("a")
  • contain Map<K,V> matcher. You can now write
val map = mapOf(Pair(1, "a"), Pair(2, "b"))
map should contain(1, "a")
  • beTheSameInstanceAs reference matcher. This is an alias for x should be theSameInstanceAs(y), allowing x should beTheSameInstanceAs(y) which fits in with new matcher style.

Changed

Replaced timeout + timeUnit with Duration (#29)

You can now write config(timeout = 2.seconds) instead of config(timeout = 2, timeoutUnit = TimeUnit.SECONDS).

Deprecated

nothing

Removed

nothing

Fixed

  • Ignored tests now display properly. kotest#43
  • Failing tests reported as a success AND a failure kotest#42