Our news feed application is ready, but it's not production ready until it is tested.
We need to add JUnit and Ktor dependencies in the build.gradle
file to test the application:
// Testing testCompile group: 'junit', name: 'junit', version: '4.12' testCompile "io.ktor:ktor-server-test-host:$ktor_version"
We have three URL endpoints in our application, two of which return JSON data for which we will use an external tool named Postman to test them.
The preceding test case gets an instance of our application and sends a get request on the specified URL, which in this is /
, aka an index URL, and it checks if the status is OK - 200
and content is Hello readers!
:
class ApplicationTest { @Test fun `check index page`() = withTestApplication(Application::main) { with(handleRequest(HttpMethod.Get, "/")) { assertEquals(HttpStatusCode.OK, response.status()) assertEquals...