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

LeoColman

05/02/2021, 3:51 PM
Maybe some sort of extension function
a

Adam S

05/02/2021, 3:55 PM
that would be good - but I can’t see the listener in the context so I don’t think it can be retrieved
l

LeoColman

05/02/2021, 3:57 PM
You could add an extension to Spec
a

Adam S

05/02/2021, 4:01 PM
I’ve tried looking but during debug I couldn’t find the container listener listed anywhere - do you know a method that could retrieve it?
here’s how it’s registered
Copy code
class KotestConfig : AbstractProjectConfig() {
  override fun listeners(): List<Listener> =
    listOf(testContainer.perSpec())
}
I know it works because the tests work
d

dave08

05/02/2021, 4:09 PM
Maybe
defaultConfig.listeners
in any TestScope?
Maybe search for it there and cast it back to the instance you need.
a

Adam S

05/02/2021, 4:16 PM
I’ve tried looking through loads of methods while debugging and couldn’t see any listener
maybe it’s in there somewhere but debugging this many nested lambdas is really difficult
d

dave08

05/02/2021, 4:22 PM
Or just save it as a global lazy val in ProjectConfig and refer to it from there? The listener instance is the same, it just starts and stops the containers every test...
a

Adam S

05/02/2021, 4:30 PM
I’m working on setting something like that up. I just hoped there was an included solution for passing variables into Specs based on config
s

sam

05/02/2021, 7:05 PM
I would do somthing along the lines of what Dave suggests. Make the listener a val in your config. It doesn't even need to be lazy.
Copy code
object GlobalConfig : AbstractProjectConfig() {
   val testContainer = ...
   override fun listeners(): List<Listener> {
      return listOf(testContainer.perSpec())
   }
}
Then you can just do
GlobalConfig.testContainer
Note that the config is an object here, not a class
The container itself still won't be started/stopped until each spec is created
6 Views