public class AssertKt
| Modifier and Type | Method and Description |
|---|---|
static <T> void |
all(Assert<? extends T> $receiver,
kotlin.jvm.functions.Function1<? super assertk.Assert<? extends T>,kotlin.Unit> f)
All assertions in the given lambda are run.
|
static <T> Assert<T> |
assert(T actual,
java.lang.String name)
Asserts on the given value with an optional name.
|
static <T> void |
assert(T actual,
java.lang.String name,
kotlin.jvm.functions.Function1<? super assertk.Assert<? extends T>,kotlin.Unit> f)
Deprecated.
|
static <T> AssertBlock<T> |
assert(kotlin.jvm.functions.Function0<? extends T> f)
Asserts on the given block. You can test that it returns a value or throws an exception.
|
static void |
assertAll(kotlin.jvm.functions.Function0<kotlin.Unit> f)
Runs all assertions in the given lambda and reports any failures.
|
static java.lang.Throwable |
catch(kotlin.jvm.functions.Function0<kotlin.Unit> f)
Catches any exceptions thrown in the given lambda and returns it. This is an easy way to assert on expected thrown
exceptions.
|
public static <T> Assert<T> assert(T actual, java.lang.String name)
Asserts on the given value with an optional name.
assert(true, name = "true").isTrue()
public static <T> void assert(T actual,
java.lang.String name,
kotlin.jvm.functions.Function1<? super assertk.Assert<? extends T>,kotlin.Unit> f)
Asserts on the given value with an optional name. All assertions in the given lambda are run.
assert("test", name = "test") {
startsWith(4)
endsWith("t")
}
public static <T> void all(Assert<? extends T> $receiver, kotlin.jvm.functions.Function1<? super assertk.Assert<? extends T>,kotlin.Unit> f)
All assertions in the given lambda are run.
assert("test", name = "test").all {
startsWith("t")
endsWith("t")
}
public static <T> AssertBlock<T> assert(kotlin.jvm.functions.Function0<? extends T> f)
Asserts on the given block. You can test that it returns a value or throws an exception.
assert { 1 + 1 }.returnedValue {
isPositive()
}
assert {
throw Exception("error")
}.thrownError {
hasMessage("error")
}
public static void assertAll(kotlin.jvm.functions.Function0<kotlin.Unit> f)
Runs all assertions in the given lambda and reports any failures.
public static java.lang.Throwable catch(kotlin.jvm.functions.Function0<kotlin.Unit> f)
Catches any exceptions thrown in the given lambda and returns it. This is an easy way to assert on expected thrown exceptions.
val exception = catch { throw Exception("error") }
assert(exception).isNotNull {
hasMessage("error")
}