phldavies
07/07/2025, 3:02 PMshould(matcher: (T) -> Unit)
inline as part of 6.x? Possible the same for shouldNotBeNull
phldavies
07/07/2025, 3:04 PMshould
and shouldBeTypeOf
taking (T) -> Unit
and shouldNotBeNull
taking T.() -> Unit
?Alex Kuznetsov
07/07/2025, 3:27 PMKlitos Kyriacou
07/07/2025, 4:04 PMshould(matcher: (T) -> Unit)
doesn't seem to bring any added benefit over Kotlin scope functions. The latter are indeed inline
. So if you really need should
to be inline, just replace it with `with`:
Instead of: someString should { it shouldStartWith "abc"; it shouldNotContain "xyz" }
Do this: someString.let { it shouldStartWith "abc"; it shouldNotContain "xyz" }
Or: with(someString) { this shouldStartWith "abc"; this shouldNotContain "xyz" }
phldavies
07/07/2025, 4:08 PMshould
being made inline
is to support suspend
in the block.
i.e. httpResponse should { it.bodyAsText() shouldContain "abc" }
Indeed we have been using .also
instead of should
in some places due to this, however the purpose of the should
method is to provide the better semantics when writing tests.sam
07/07/2025, 5:39 PMsam
07/07/2025, 5:39 PMsomeString.shouldStartWith("abc").shouldNotContain("xyz")
sam
07/07/2025, 5:40 PMsomePossibleNullString.shouldNotBeNull().shouldContain("foo")
phldavies
07/07/2025, 5:41 PMshould
for grouping several property assertions:
myResult should {
it.id.shouldNotBeEmpty()
it.age shouldBeLessThan 12
}
etcphldavies
07/07/2025, 5:44 PMshouldBlah
function returns Unit
(i.e. shouldHaveStatus
in the ktor assertions)sam
07/07/2025, 5:44 PMAlex Kuznetsov
07/07/2025, 5:46 PMsam
07/07/2025, 5:46 PMsam
07/07/2025, 5:47 PMsam
07/07/2025, 5:47 PMAlex Kuznetsov
07/07/2025, 5:47 PMshould
phldavies
07/07/2025, 5:49 PMshouldNotBeNull
myResult shouldNotBeNull {
id.shouldNotBeEmpty()
age shouldBeLessThan 12
}
which is a handy way of writing your own "shouldBeValidResponse()` style helpers
Either way, marking the two historic functions (assuming shouldNotBeNull taking a block is historic too) as inline should be of very little impact but allows for the use of suspend calls inside.sam
07/07/2025, 7:36 PMphldavies
07/07/2025, 7:37 PMsam
07/07/2025, 7:38 PMsam
07/07/2025, 7:38 PM