We are using kotlin test in some places and I'm tr...
# test
e
We are using kotlin test in some places and I'm trying to chain some calls. Is it correct usage?
Copy code
with(assertIs<HomeFeedResult.Error>(repository.fetchHomePageFeedsMetaData(10))) {
            with(assertIs<HomeFeedException.ServerError>(exception)) {
                assertEquals(404, code)
                assertTrue(message.orEmpty().contains("Server error 404"))
            }
        }
Looks a bit hard to read and assertK is doing it in a better way.
j
Copy code
val foo: Foo = …
with(foo) { … }
👍🏼 1
c
You don't need to group everything like that
Copy code
val metadata = repository.fetchHomePageFeedsMetaData(10)
assertIs<HomeFeedResult.Error>(metadata)
val exception = assertIs<HomeFeedException.ServerError>(metadata.exception)
assertEquals(404, exception.code)
assertTrue(exception.message.orEmpty().contains("Server error 404"))
IMO simpler code is easier to read, the nesting doesn't help much here
e
Then you get compiler warnings that assertIs result is not used
Sorry missed that part here
c
Ah, they forgot the
@IgnorableReturnValue
Reported: KT-85068 Kotlin-test: assertIs is missing @IgnorableReturnValue
assertIs
smart-casts the value so you shouldn't have to create a variable, you can use your existing one
e
Thanks!