Pihentagy
06/27/2023, 4:01 PMexpectThat(result) {
get { statusCode }.isEqualTo(HttpStatus.OK)
get { body }.isNotNull().and {
get { elements }.and {
hasSize(1)
expectThat(first().subject) {
get { coordinates }.isEqualTo(listOf(coord))
get { networkType }.isEqualTo(NetworkType.SWITCH)
}
}
}
}Saharath Kleips
06/27/2023, 5:48 PMget(HttpResponse::statusCode).isEqualTo(…) over get { statusCode }. In my experience needing the lambda version is an edge case.
• You probably should be using that(first().subject) rather than expectThat but to me it’s probably another get ?
• StriKT also has functions for asserting collections: So I’d probably write some variation of get(Subject::coordinates).containsExactlyInAnyOrder(coord)
I think in general, StriKT lets you write these assertions in a way that makes the output of a test result become immediately clear and specific as to what failed. So, I wouldn’t say any of it is necessarily wrong (the assertions still ultimately work) but reading the result of a failure could be improved.robfletcher
06/27/2023, 9:08 PMexpectThat(result) {
get { statusCode }.isEqualTo(HttpStatus.OK)
get { body }
.isNotNull().get { elements }
.hasSize(1)
.withFirst {
get { coordinates }.isEqualTo(listOf(coord))
get { networkType }.isEqualTo(NetworkType.SWITCH)
}
}
You shouldn’t nest an expect method inside another one. Unfortunately there’s not really a way for me to prevent that, but it can create unpredictable results.
The and method is for grouping multiple assertions and there are a couple of places where you only really have one thing inside of it, so it’s not necessary.robfletcher
06/27/2023, 9:14 PMEric
06/27/2023, 9:15 PMsingle() instead of hasSize(1).withFirst { ... }?robfletcher
06/27/2023, 9:15 PM.subject there, but hopefully you get the idearobfletcher
06/27/2023, 9:15 PMsingle is basically hasSize(1).first(). I went for withFirst in order to group the 2 assertions on that elementPihentagy
06/28/2023, 7:33 AMPihentagy
06/28/2023, 7:33 AMPihentagy
06/28/2023, 7:41 AM.hasSize(1).withFirst() { ... }
to
.single().and() { ... }
Shouldn't be a single version with blocks, so that I can write:
.single() { ... }robfletcher
06/28/2023, 5:43 PMwithSingle { } yeahrobfletcher
06/28/2023, 5:43 PM.single().and { } as you say)Pihentagy
06/28/2023, 8:40 PM