https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

Thiyagu

01/17/2020, 6:27 PM
Hi All, can anyone help me how to write unit test for this below method?
Copy code
fun pollMessages(): Flow<Message> {

        return channelFlow {

            repeat(noOfReceivers) {
                launch {
                    val messages = sqsClient.fetchMessages()
                    messages.forEach {
                        send(it)
                    }

                }
            }
        }
    }
l

Luke Rohde

01/17/2020, 6:28 PM
what are you trying to test?
t

Thiyagu

01/17/2020, 6:29 PM
Ok.. I want to this method is returning a flow with type as
Message
by mocking sqs client.
a

Animesh Sahu

01/18/2020, 10:35 AM
I mean like you can mock sqs client and attach a collect() to the returned flow and check if mocked messages are the same as you got from the flow.
4 Views