hello guys :wink: my test (describe spec) ignore i...
# kotest
ł
hello guys 😉 my test (describe spec) ignore included tests (test factories). Do you have any idea?
s
You mean they're not picked up? We'd need to see code
ł
Factory:
Copy code
fun `when device auth headers are missing`(apiTestEnv: ApplicationEngineEnvironment, path: String) = describeSpec {
    describe("when device auth headers are missing") {
        it("should returns status 401") {
            withApplication(apiTestEnv) {
                val call = handleRequest(uri = path, method = HttpMethod.Get)

                call.response.status() shouldBe HttpStatusCode.Unauthorized
            }
        }
    }
}
Test:
Copy code
class AudioFilesHandlerTest : ApiModuleTest() {

    private val deviceAuthenticationService = mockk<DeviceAuthenticationService>()
    private val saveAudioFileService = mockk<SaveAudioFileService>()

    override val koinModules: Module
        get() = module {
            single { deviceAuthenticationService }
            single { saveAudioFileService }
        }

    init {
        describe("AudioFilesHandler") {
            val audioFilesUri = "/api/audio-files"

            describe("GET $audioFilesUri") {
                include(`when device auth headers are missing`(apiTestEnv, audioFilesUri))

                describe("when device is registered") {
                    val product = createProduct()
                    val device = createDevice(product)
                    val verifiedDevice = createVerifiedDevice(device)

                    every {
                        deviceAuthenticationService.validate(product.productId, device.deviceId)
                    } returns verifiedDevice

                    it("should returns 200") {
                        withApplication(apiTestEnv) {
                            val call = handleRequest(uri = audioFilesUri, method = HttpMethod.Get) {
                                val boundary = "WebAppBoundary"
                                addHeader(ContentType, FormData.withParameter("boundary", boundary).toString())
                                addHeader("productId", product.productId)
                                addHeader("deviceId", device.deviceId)
                            }

                            call.response.status() shouldBe HttpStatusCode.OK
                        }
                    }
                }
            }
        }
    }
}
and my ApiModuleTest wrapper:
Copy code
abstract class ApiModuleTest : DescribeSpec(), KoinTest {
    protected lateinit var apiTestEnv: ApplicationEngineEnvironment

    abstract val koinModules: Module

    override fun beforeSpec(spec: Spec) {
        super.beforeSpec(spec)
        startKoin {
            modules(koinModules)
        }
    }

    override fun beforeTest(testCase: TestCase) {
        super.beforeTest(testCase)
        apiTestEnv = createTestEnvironment {
            config = HoconApplicationConfig(ConfigFactory.load("api.conf"))
        }
    }

    override fun afterSpec(spec: Spec) {
        super.afterSpec(spec)
        stopKoin()
    }
}
line `include(`when device auth headers are missing`(apiTestEnv, audioFilesUri))` isn’t called
that I think
s
Factories cannot be inserted in nested tests only at the top level. You could make a regular function and call that.
ł
ouuu….
where is a sense in this?