5

I already have OkHttp MockWebServer running with my Espresso UI tests for Android. Everything is working fine.

Now I want to have MockWebServer standalone running on my localhost to other clients to be able to connect to it. Clients like Appium, internet browser etc. which will get mocked response from the server. I want to reuse already prepared mocking code and not using something like Wiremock.

My approach is to build standalone jar artifact in separate Java/Kotlin project which will run on my machine using cmd line. The sample code is below.

The problem is I'm not able to connect to shown URL address of the server. I'm trying ping commands etc. But the server is not found.
Don't know what to try or setup next.
Thanks

Error message:

ping http://kubernetes.docker.internal:62037 
Ping request could not find host http://kubernetes.docker.internal:62037. Please check the name and try again.

MockServer:

object MockServer {

fun init() {
    GlobalScope.launch(Dispatchers.IO) {
        val mockWebServer = MockWebServer()
        mockWebServer.start()
        println("Server url: " + mockWebServer.url("").toString())
    }
}

Main class:

fun main(args: Array<String>) {
   MockServer.init()
   println("MockServer running")
   Thread.sleep(30000) // main thread is sleeping but server is running in different thread
   println("MockServer exit")
   exitProcess(0)
}
Warlock
  • 2,481
  • 4
  • 31
  • 45
  • Does this answer your question? [Docker Desktop installation on WIndows causes InetAddress.getLocalhost().getCanonicalHostname() to return host.docker.internal](https://stackoverflow.com/questions/71032544/docker-desktop-installation-on-windows-causes-inetaddress-getlocalhost-getcano) – Redlab Jul 06 '23 at 15:09
  • Unfortunately this is not solver to my problem, but thanks for help. – Warlock Jul 14 '23 at 08:13

0 Answers0