calidion
01/13/2025, 5:15 AM@RunWith(AndroidJUnit4::class)
class ServerInstrumentedTest {
@Test
fun should_test_server_client() = runTest {
val app = ApplicationProvider.getApplicationContext<MainApplication>()
val preference = app.preference
val setting = Settings(preference)
setting.localServerPort = 0
val db = ZzDatabase.getDatabase(app.applicationContext)
db.peer().clearData()
val port = setting.localServerPort
PeerServer.start(app, "127.0.0.1", port)
val timeStamp = Time.now()
val peer = Peer(
"127.0.0.1",
port,
AddressType.IPV4,
createdAt = timeStamp, updatedAt = timeStamp
)
runBlocking {
val peerClient = PeerClient(app, peer)
val response01 = peerClient.client.get("<http://www.baidu.com/>")
// val response01 = peerClient.client.get(peer.baseUrl + "/")
assertEquals(HttpStatusCode.OK, response01.status)
// assertEquals("Hello From ZZ!\n", response01.bodyAsText())
}
}
It can access out side servers, but not the local one. and this code can not be put inside android InstrumentedTest for my server needs reading configurations from android database
@Test
fun testRoot() = testApplication {
application {
module()
}
val response = client.get("/")
assertEquals(HttpStatusCode.OK, response.status)
assertEquals("Hello, world!", response.bodyAsText())
}
Aleksei Tirman [JB]
01/13/2025, 9:36 AMcalidion
01/13/2025, 9:40 AMAleksei Tirman [JB]
01/13/2025, 10:51 AMcalidion
01/13/2025, 12:55 PMcalidion
01/13/2025, 12:55 PMcalidion
01/13/2025, 1:21 PM