jeudi 19 mars 2020

Testing Micronaut POST Request without hitting the URL - Mocking - Kotlin

I would like to Unit Test my Kotlin class, which makes a POST request using micronaut's RxHttpClient.

The code I want to test (simplified):

fun makePost() {
    val httpRequest = HttpRequest.POST<Any>(uri, json).contentType(MediaType.APPLICATION_JSON)
    return httpClient.exchange(httpRequest, String::class.java)
        .singleOrError()
        .map { response ->
            println("Success")
        }.doOnError { error ->
            println("Error"))
        }
}

I don't want it to hit the actual url of the post, I'm looking for a way to "mock" the response.

I already tried to use mock-server and mocking the HttpClient using mockito, without success.

Can someone help me, or give me any advice about what should I do? Thanks

Aucun commentaire:

Enregistrer un commentaire