https://github.com/lovef/kotlin-assert-utils
A set of assert utilities for JUnit testing with Kotlin
https://github.com/lovef/kotlin-assert-utils
assertion-library junit4 kotlin testing testing-tools unit-testing
Last synced: about 2 months ago
JSON representation
A set of assert utilities for JUnit testing with Kotlin
- Host: GitHub
- URL: https://github.com/lovef/kotlin-assert-utils
- Owner: lovef
- License: apache-2.0
- Created: 2017-08-22T19:06:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-08T21:23:13.000Z (over 6 years ago)
- Last Synced: 2023-11-10T13:03:45.509Z (over 2 years ago)
- Topics: assertion-library, junit4, kotlin, testing, testing-tools, unit-testing
- Language: Kotlin
- Homepage:
- Size: 249 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/lovef/kotlin-assert-utils)
[](https://maven-badges.herokuapp.com/maven-central/se.lovef/kotlin-assert-utils)
[](https://bintray.com/lovef/maven/kotlin-assert-utils/_latestVersion)
# Kotlin assert utils
A set of assert utilities for JUnit testing with Kotlin
## Example
```kotlin
import org.junit.Test
import se.lovef.assert.v1.*
class ExampleTest {
@Test fun `example test`() {
1 shouldEqual 1
{ 1 shouldEqual 2 } throws Error::class
1 shouldBeLessThan 2 shouldBeLessThan 3
1 shouldBeCloseTo 1.1 tolerance 0.2
"my 1337 string" shouldContain "my" shouldContain 1337 shouldContain "string"
"my 1337 string" shouldNotContain "shit"
null.shouldBeNull()
("123" as String?).shouldNotBeNull().length shouldEqual 3
val exception = Exception()
; { throw exception } throws exception
{ { throw exception } throws Exception() } throws exception
{ { } throws exception } throws NotThrownError::class
{ "1 is 2" proof { 1 shouldEqual 2 } }
.throws(Error::class)
.message shouldEqual "1 is 2"
true.shouldBeTrue();
{ null.shouldBeTrue() } throws Error::class
listOf(1, "2", null).shouldNotBeEmpty() shouldContain "2" shouldNotContain -1
{ listOf(1, 2, 3) shouldEqual intArrayOf(1, 2, 3) }
.throws(Error::class)
.message shouldEqual """|
|Expected: [1, 2, 3]
|Got: [1, 2, 3]
""".trimMargin();
{ 1337 shouldEqual "1337" }
.throws(Error::class)
.message shouldEqual """|
|Expected: "1337"
|Got: 1337
""".trimMargin()
listOf(1, 3, 5) shouldAll { it % 2 shouldEqual 1 }
}
}
```
## Setup
```gradle
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.61"
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
testImplementation "se.lovef:kotlin-assert-utils:0.10.1"
}
repositories {
mavenCentral()
}
```