I have a simple program in Ktor. It runs perfectly, but when I run the unit testing class it only throws this error: "expected:<200 OK> but was:<404 Not Found>"
This is my unit test code:
class ApplicationTest {
@Test
fun testRoot() = testApplication {
val response = client.get("/")
assertEquals(HttpStatusCode.OK, response.status)
}
@Test
fun testStart() = testApplication {
val response = client.post("/start")
assertEquals(HttpStatusCode.OK, response.status)
}
}
This is my Application.kt:
const val enableHTTPS = false
const val portHTTP = 80
const val portHTTPS = 7001
lateinit var environment: ApplicationEngineEnvironment
fun main() {
initEnvironment()
embeddedServer(Netty, environment = environment).start(wait = true)
}
My routing file is:
fun Application.configureRouting() {
routing {
get {
call.respond(ApiDetails())
}
post("/start") {
call.response.status(HttpStatusCode.OK)
}
post("/move") {
val gameDetails: GameDetails = call.receive()
val move = BasicStrategy().move(gameDetails, application)
call.respond(move)
}
post("/end") {
}
}
}