Unresolved reference: module in testApplication() from another subproject

48 views Asked by At

I have a Ktor project, which has sub projects. The Application.kt is in one subproject and the routes are in another sub project. I am writing unit tests for the routes using testApplication(). However when I call module(client) from the sub project, I am getting below error:

Unresolved reference: module

Code(unit test works in application sub project): application sub-project: /app-main/src/main/kotlin/com/app/Application.kt

test application sub-project(test case works here): /app-main/src/test/kotlin/com/app/ApplicationTest.kt

    // GIVEN: User is created and present.
    // WHEN: Application is started.
    // THEN: expect that application starts successfully serving login.
    @Test
    fun User_ApplciationStart_LoginSuccessful() = testApplication {
        val client = createClient {

        }
        externalServices {

        }

        application {
            module(client) **// ====> this works here**
        }

        environment {

        }

        routing {
            get("/login-test") {
                call.sessions.set(UserSession("..", ".."))
            }
        }

        val loginResponse = client.get("/login-test")
        assertTrue {
            ... ...
        }
    }

route sub project(unit test does not work in this sub project): /route/src/main/kotlin/com/route/route1.kt module1.kt in this directory contains: fun Application.mainModule()

test route sub project(same test case does not work here):

/route/src/test/kotlin/com/route/route1Test.kt

    // GIVEN: User is logged in.
    // WHEN: user tries to access PATH page.
    // THEN: expect that page access successful.
    @Test
    fun UserLoggedIn_GetPATH_PageSuccessful() = testApplication {
        environment {
        }

        val client = createClient {

        }

        application {
            module(client) **// =====>>> this gives error**
        }

        routing {
            get("/login-test") {
                call.sessions.set(UserSession("..", ".. ..")) //==> without module sessions does not work
            }
        }

        client.get("/login-test")
        val resp = client.get(custom_path)

        assertEquals(HttpStatusCode.OK, resp.status)
    }

Tried import, but did not work.

0

There are 0 answers