kotlin-assert-utils

Kotlin JUnit 4 Assert Utilities

License

License

Categories

Categories

Kotlin Languages
GroupId

GroupId

se.lovef
ArtifactId

ArtifactId

kotlin-assert-utils
Last Version

Last Version

0.10.1
Release Date

Release Date

Type

Type

jar
Description

Description

kotlin-assert-utils
Kotlin JUnit 4 Assert Utilities
Project URL

Project URL

https://github.com/lovef/kotlin-assert-utils
Source Code Management

Source Code Management

https://github.com/lovef/kotlin-assert-utils

Download kotlin-assert-utils

How to add to project

<!-- https://jarcasting.com/artifacts/se.lovef/kotlin-assert-utils/ -->
<dependency>
    <groupId>se.lovef</groupId>
    <artifactId>kotlin-assert-utils</artifactId>
    <version>0.10.1</version>
</dependency>
// https://jarcasting.com/artifacts/se.lovef/kotlin-assert-utils/
implementation 'se.lovef:kotlin-assert-utils:0.10.1'
// https://jarcasting.com/artifacts/se.lovef/kotlin-assert-utils/
implementation ("se.lovef:kotlin-assert-utils:0.10.1")
'se.lovef:kotlin-assert-utils:jar:0.10.1'
<dependency org="se.lovef" name="kotlin-assert-utils" rev="0.10.1">
  <artifact name="kotlin-assert-utils" type="jar" />
</dependency>
@Grapes(
@Grab(group='se.lovef', module='kotlin-assert-utils', version='0.10.1')
)
libraryDependencies += "se.lovef" % "kotlin-assert-utils" % "0.10.1"
[se.lovef/kotlin-assert-utils "0.10.1"]

Dependencies

compile (1)

Group / Artifact Type Version
junit : junit jar 4.12

runtime (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.1.2

Project Modules

There are no modules declared in this project.

Build Status Maven Central Download

Kotlin assert utils

A set of assert utilities for JUnit testing with Kotlin

Example

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: <int[]> [1, 2, 3]
                |Got:      <ArrayList> [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

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()
}

Versions

Version
0.10.1
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.0
0.4.0
0.3.0
0.2.1
0.2.0
0.1.1
0.1.0
0.0.3