https://kotlinlang.org logo
#kotest
Title
# kotest
j

James Eschner

04/04/2022, 9:32 PM
How do I use the SystemEnvironmentProjectListener (or really any externally defined project listener) in my project? I found a README that says to do this:
Copy code
class ProjectConfig : AbstractProjectConfig() {

    override fun listeners(): List<TestListener> = listOf(SystemEnvironmentProjectListener("foo", "bar"))

}
but AbstractProjectConfig::listeners is deprecated and the deprecation message, “`Use extensions."` , isn’t the most helpful. I would like to define the listener once for the whole project. * Not a contribution *
e

Emil Kantis

04/04/2022, 9:55 PM
Try this:
Copy code
object EnvironmentExtension : TestCaseExtension {
   override suspend fun intercept(testCase: TestCase, execute: suspend (TestCase) -> TestResult): TestResult {
      return withEnvironment("" to "") {
         execute(testCase)
      }
   }
}

object ProjectConfig : AbstractProjectConfig() {
   override fun extensions() = listOf(EnvironmentExtension)
}
I can try updating the readme if it works. Perhaps we could also raise an issue about creating a replacement for
SystemEnvironmentProjectListener
j

James Eschner

04/04/2022, 10:10 PM
Lol, I didn’t even realize
extensions
was a function in
AbstractProjectConfig
. I thought when the message said “extensions” it was talking about extensions in the abstract 😅
It looks like a
Listener
is an
Extension
so this might just work, trying now…
e

Emil Kantis

04/04/2022, 10:17 PM
Ah, convenient 🙂
12 Views