Testing the Service and Modularizing the Application
Learn how to test the routes in a Ktor application and how we can modularize the app.
We'll cover the following...
We'll cover the following...
Writing a test in the AppTest.kt file
To write our first test, let’s create a new file called AppTest.kt under the src/test/kotlin directory.
Now, let’s add a new dependency:
dependencies {
     ...
     testImplementation("io.ktor:ktor-servertests:$ktorVersion")
}
See the build.gradle.kts file for step 5 in the code.
Next, let’s add the following contents to our AppTest.kt file:
internal class ServerTest {
     @Test
     fun testStatus() {
         withTestApplication {
             val response = handleRequest(HttpMethod.Get,
                 "/status").response
             assertEquals(HttpStatusCode.OK,
 ...