studio.forface:assert4k

Multiplatform Kotlin assertions

Лицензия

Лицензия

The Apache Software License - Version 2.0
Группа

Группа

studio.forface
Идентификатор

Идентификатор

assert4k-jvm
Последняя версия

Последняя версия

0.7.1
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

studio.forface:assert4k
Multiplatform Kotlin assertions
Ссылка на сайт

Ссылка на сайт

https://github.com/4face-studi0/Assert4K
Система контроля версий

Система контроля версий

https://github.com/4face-studi0/Assert4K

Скачать assert4k-jvm

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.32
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.32

runtime (3)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-test jar 1.4.32
org.jetbrains.kotlin : kotlin-test-common jar 1.4.32
org.jetbrains.kotlinx : kotlinx-coroutines-core-jvm jar 1.4.3

Модули Проекта

Данный проект не имеет модулей.

Assert4k

METHOD LINE COMPLEXITY

Assert4k is a Kotlin Multiplatform assertion DSL. It currently supports Jvm and Js only, but many other platform will come soon.

The focus of Assert4k is to take advantage of the power of Kotlin for create a beautiful human readable assertion DSL. It covers a big variety of use cases and ensure you to able to write your assertion in the same way you would write to a friend. Forgot about commas and parenthesis!

All the code is available under the same package assert4k.*, include it in your IDE settings for avoid to search what you need between the suggestions.

( Preferences -> Editor -> Code Style -> Kotlin -> Packages to Use with import '* )

assert that developing `is` `fun`

Usage

Include in your Gradle dependencies:

testImplementation("studio.forface:assert4k:<last_version>")

and start having fun!

There are many alternatives for fits everyone's tastes. Like:

  • `null` or Null
  • `not equals` or notEquals

For fail with a custom message, use / "This is my message", it applies to almost every assertion.

assert that greeting equals "good night" / "It's too early for sleep!!" 

Extensibility - custom assertions

infix fun Asserter<User>.`older than`(age: Int) =
    assert that (value.age > age) / { 
        "User too young: Expected age to be greater than <$age> but is <$value>" 
    }

assert that someUser `older than` 15
assert that someUser *{
    it `older than` 15
    +name equals "Davide"
}

Some assertions

General (any.kt and null.kt)
assert that MyClass("Hello") equals MyClass("Hello")

assert that today.isSunny

assert that { tomorrow.isSunny }

assert that myObject `is` `null`
Strings (string.kt)
assert that "bye bye" contains "bye"

assert that "bye bye" `contains no case` "BYE"

assert that "bye bye" contains ("BYE" no case)
Numbers (number.kt)
assert that 5 `greater than` 5.1f

assert that 5 equals "5"

assert that 1.5 between 1 .. 2

assert that 1.5 between 1.4 .. 1.6
Collections (collection.kt)
assert that listOf(1, 2, 3) contains 3

assert that emptyList<Int> `is` empty

assert that null `is` empty or `null`
Catch exception(fail.kt)
assert that fails { throw Exception() }

assert that fails<IllegalStateException> { throw IllegalStateException() }

assert that fails { throw Exception("Oops!") } with "Oops!"

assert that coFails {
  delay(100)
  throw Exception()
}
Multiple assertions
assert that User(name = "Davide", age = 29) *{
    it equals User("Davide", 29)

    +name `equals no case` "davide"
    // invoke operator can be used on some types, like number, which already
    // have the `unaryPlus` as language feature
    +age() between 25 .. 35
}

Версии библиотеки

Версия
0.7.1