How can I store a value which can be accessed in m...
# kotest
p
How can I store a value which can be accessed in multiple tests? I have several files each containing a StringSpec class with tests in it, and have added a project level config with a beforeAll function in it, which is being called before tests run. I'm currently trying to add a variable in that listener which can then be accessed by any of the tests, but not sure how to do this or what is the best way (I'm quite new to Kotlin). Can anyone help to point me in the right direction please?
s
Immutable value?
p
Yes I think it could be immutable, but not in the way I'm currently doing it. I found a way to do this, here's an example, not real code just to give an idea of what I'm trying to do: My project level config:
Copy code
object MyConfig : AbstractProjectConfig() {
    var usefulNumberID = 0

    override fun beforeAll() {
        usefulNumberID = getUsefulIdFromDB()
    }
}
Then in a test I can do something like:
Copy code
val testID = MyConfig.usefulNumberID
I think this will work for me, does this seem sensible or is there a better way?
s
Global object works. Can be anywhere not just in config
p
Yeah it might as well be a global variable instead, I might try it like that, thanks 🙂