In kotlintest I was able to add arbitrary metadata...
# kotest
b
In kotlintest I was able to add arbitrary metadata via the
testContext
member in a
ShouldScope
, does something equivalent exist in kotest?
Looking through
ShouldSpecContextScope
I haven't found anything, but hoping maybe that feature is done another way now
w
I looked for such feature some time ago (basically any way to add an object or key-value map) but didn’t find one. What’s your use case?
b
I have some tests that validate behavior based on values from configuration, so I had a helper
withConfig(...)
that set a config and then another helper
getValue
to retrieve a value from that set config. I ended up having to create my own scope class which has the configuration set. So I had to do it within that scope, i.e.:
Copy code
withConfig(...) {
  ...
  getValue(...) shouldBe ...
}
w
Right, that reminded me: since tests are coroutines, maybe you can put whatever data you want in its
coroutineContext
?
b
Hm, yeah that's an interesting idea
s
Can you just create a variable in the scope and reference that ?
You don't need to assign it and then pull it back out ?
b
Yeah the helpers I added do write/read a variable in the scope
It by no means requires the metadata helpers, but they were nice.
s
We can always add new features 🙂
Can you write up a pseudo code example of what you were using them for ?
b
Ya, I'll grab link to the old test file in GitHub when I get a minute
In this scenario, the after may be best anyway because it eliminates any chance of issues with sharing the same instance. ¯\_(ツ)_/¯