public class AssertKt
| Modifier and Type | Method and Description |
|---|---|
static <T> void |
all(Assert<? extends T> $receiver,
java.lang.String message,
kotlin.jvm.functions.Function1<? super assertk.Assert<? extends T>,kotlin.Unit> body)
All assertions in the given lambda are run.
|
static <T> Assert<T> |
assert(T actual,
java.lang.String name)
Deprecated.
|
static <T> AssertBlock<T> |
assert(kotlin.jvm.functions.Function0<? extends T> f)
Deprecated.
|
static void |
assertAll(kotlin.jvm.functions.Function0<kotlin.Unit> f)
Runs all assertions in the given lambda and reports any failures.
|
static <T> Assert<T> |
assertThat(T actual,
java.lang.String name)
Asserts on the given value with an optional name.
|
static <T> Assert<T> |
assertThat(kotlin.reflect.KProperty0<? extends T> getter,
java.lang.String name)
Asserts on the given property reference using its name, if no explicit name is specified. This method
should be preferred in cases, where property references can be used, as it uses the property's name
for the assertion automatically. The name may optionally be overridden, if needed.
|
static <T> AssertBlock<T> |
assertThat(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 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> Assert<T> assertThat(T actual, java.lang.String name)
Asserts on the given value with an optional name.
assertThat(true, name = "true").isTrue()
public static <T> Assert<T> assertThat(kotlin.reflect.KProperty0<? extends T> getter, java.lang.String name)
Asserts on the given property reference using its name, if no explicit name is specified. This method should be preferred in cases, where property references can be used, as it uses the property's name for the assertion automatically. The name may optionally be overridden, if needed.
data class Person(val name: String)
val p = Person("Hugo")
assertThat(p::name).contains("u")
public static <T> void all(Assert<? extends T> $receiver, java.lang.String message, kotlin.jvm.functions.Function1<? super assertk.Assert<? extends T>,kotlin.Unit> body)
All assertions in the given lambda are run.
assertThat("test", name = "test").all {
startsWith("t")
endsWith("t")
}
message - An optional message to show before all failures.body - The body to execute.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 <T> AssertBlock<T> assertThat(kotlin.jvm.functions.Function0<? extends T> f)
Asserts on the given block. You can test that it returns a value or throws an exception.
assertThat { 1 + 1 }.returnedValue {
isPositive()
}
assertThat {
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") }
assertThat(exception).isNotNull().hasMessage("error")