Sebastian Schuberth
06/11/2025, 2:32 PMKlitos Kyriacou
06/11/2025, 3:44 PMval result: MyResultType
mockkObject(SomeObject) {
every { SomeObject.foo() } returns "bar"
result = callUnitUnderTest()
}
result.a shouldBe 1
result.b shouldBe 2
The idea was to keep the time the object is mocked to a minimum. The object doesn't have to remain mocked while I'm doing the assertions.
Unfortunately, the Kotlin compiler gives an error saying result
is reassigned inside the lambda and uninitialized outside the lambda. This is because it doesn't know that the lambda is guaranteed to be called exactly once. This can be fixed by the use of contracts. Is there any chance it can be done in a future release?phldavies
06/11/2025, 7:20 PMJustin Tullgren
06/13/2025, 3:00 PMScott Fedorov
06/16/2025, 6:29 PMRob Elliot
06/18/2025, 8:38 AM@RepeatUntilFailure
. What's the Kotest equivalent?Benoît Liessens
06/20/2025, 6:36 AMshouldBe ….
) and negative (shouldNotBe …
) which made me realise every Kotest matcher is `invert()`able!
To my surprise neither Hamcrest nor AssertJ matcher have such capability. Really nice! 👏Bernd Prünster
06/21/2025, 6:35 AMAlex Kuznetsov
06/25/2025, 6:13 PMMarkRS
06/27/2025, 3:02 PMval someFloats = listOf(1F, 2F, 4.2F)
withData<Float>({"Testing $someFloat"}, someFloats) { someFloat -> &tc
and the compiler complains about $someFloat in the name function (with our without .toString()).
Full(er) disclosure, it's the seventh nested withData, but without the name function it works, and I've tried reducing the number of nests and it still complains.
Bug?hantsy
06/29/2025, 1:49 AMAnnotationSpec
working well.
@Import(TestcontainersConfiguration::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class DemoApplicationAnnotationSpec : AnnotationSpec() {
@LocalServerPort
private var port: Int = 8080
lateinit var client: WebClient
@BeforeEach
fun setUp() {
client = WebClient.create("<http://localhost>:$port")
}
@Test
fun `get all posts`() {
client.get()
.uri("/posts")
.accept(MediaType.APPLICATION_JSON)
.exchangeToFlux {
assertThat(it.statusCode()).isEqualTo(HttpStatus.OK)
it.bodyToFlux(Post::class.java)
}
.test()
.expectNextCount(2)
.verifyComplete()
}
}
How to convert this to use StringSpec
FuncSpec
,etc., especially I do not know where to use the Spring special annotation to inject beans, such as LocalServerPort
, MockkBean
, etc.
I have tried to use LocalServerPort in the test class body, but it can not be accessed in the test block.
xxxStringSpec:StringSpec({
//1. @LocalServerPort is NOT allowed here
//2. The port injected in the class body(below) cannot be accessed here.
}){
@LocalServerPort
private var port: Int = 8080
}
Alexander Ioffe
06/30/2025, 6:57 AMCould not find io.kotest:kotest-framework-multiplatform-plugin-embeddable-compiler:6.0.0.M4
Bernd Prünster
06/30/2025, 8:29 AMAlexander Ioffe
06/30/2025, 3:37 PMe: java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.ir.expressions.IrConstructorCall org.jetbrains.kotlin.ir.builders.ExpressionHelpersKt.irCall(org.jetbrains.kotlin.ir.builders.IrBuilderWithScope, org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol)'
Alexander Ioffe
06/30/2025, 5:22 PMAlexander Ioffe
06/30/2025, 5:49 PMmaven { url = uri("<https://central.sonatype.com/repository/maven-snapshots>") }
doesn't seem to do anything.Bernd Prünster
06/30/2025, 6:32 PMAlexander Ioffe
06/30/2025, 8:19 PMAlexander Ioffe
06/30/2025, 8:20 PMEmil Kantis
06/30/2025, 9:15 PMAlexander Ioffe
06/30/2025, 9:16 PMEmil Kantis
06/30/2025, 9:19 PMAlexander Ioffe
06/30/2025, 9:25 PMAlexander Ioffe
06/30/2025, 9:30 PMEmil Kantis
06/30/2025, 9:32 PMAlex Kuznetsov
07/01/2025, 5:56 PMOlaf Gottschalk
07/03/2025, 12:51 PMphldavies
07/07/2025, 3:02 PMshould(matcher: (T) -> Unit)
inline as part of 6.x? Possible the same for shouldNotBeNull
Emil Kantis
07/08/2025, 2:46 PMBernd Prünster
07/10/2025, 10:53 PM