Wrote a small post about tweaking some Kotest sett...
# kotest
e
Wrote a small post about tweaking some Kotest settings related to classpath scanning in order to achieve faster test run times. Hope it's of use to someone πŸ™‚ https://kantis.github.io/posts/Faster-Kotest-startup/
πŸ‘ 1
πŸ†’ 1
s
Thanks, just going through it to review πŸ˜‰ One thing I've found: There's a typo in
kotest.framework.discovery.jar.scan.disabled
which should say
kotest.framework.discovery.jar.scan.disable
without "d".
πŸ‘ 1
thank you color 1
And IMO a linkt o the reference at https://kotest.io/docs/framework/framework-config-props.html would be great, although it unfortunately does not document the meaning of
kotest.framework.discovery.jar.scan.disable
...
...I'm looking into contributing docs for
kotest.framework.discovery.jar.scan.disable
, but I'm actually unsure of its effect. This basically toggles
ClassGraph.disableJarScanning()
when scanning for Kotest configs, but what's the actual effect when disabling this? Will only third-party JARs (of my project's dependencies) not be scanned for Kotest config, or will also JARs produced by subprojects of my own (root) project not be scanned?
e
Does Gradle use JARs for project dependencies? πŸ€” If so, then yes.
s
I believe it does not, as an optimization, to avoid actually building the JARs unless you distribute.
πŸ‘ 1
I just tried, and my (shared)
ProjectConfig
is still found despite
kotest.framework.discovery.jar.scan.disable = true
πŸ‘πŸ»
e
Adjusted the post to fix the typo'd property.. great find, thanks πŸ™‚
s
I also realized at some point that when running "Kotest"-type run configurations, those Gradle-base test properties are not taken into account, and I saw the respective warning about classpath scanning on the console. However, I'm not setting those properties in Gradle, but in
kotest.properties
which resides next to my
ProjectConfig
, and now I don't see these warnings anymore even with "Kotest"-type run configurations. Is that expected, does it actually work?
> If your project consists of many modules, it can be tedious to duplicate this configuration in each module, so I personally prefer the Gradle config. Regarding that, I simply have a
test-utils
Gradle module with my
ProjectConfig
and
kotest.properties
that all my tests depend on.
e
kotest.properties
should work w/ both types of run configuration, afaik
πŸ‘πŸ» 1
That's also an option, yes. I think some might consider it a bit tedious to set up a separate Gradle module for that, but definitely an option if you're comfortable with configuring builds
Might be worth it's own post at some point πŸ™‚
πŸ˜„ 1
s
Otherwise you could also leverage the
idea-ext
Gradle plugin to configure presets for run configurations, similar to this.
e
ohh sweet! that's a way better way of doing it πŸ™‚
l
Why not make it default behaviour for Kotest so it's fast by default ?
s
It will become the default with Kotest 6.
It's a breaking change, so it requires a major version bump, according to SemVer.
l
Ah ok thanks, I will wait for Kotest 6 then πŸ™‚
v
After disabling classpath scanning any specs that use the Spring Extension fail with
Copy code
io.kotest.engine.spec.SpecInstantiationException: Could not create instance of class com.example.Spec. Specs must have a public zero-arg constructor.
Does this change how we are supposed to activate extensions?
e
Yes. You need to create a Kotest config and declare the extension there
I can give an example on how to do this later when I’m at the computer
v
So extensions must be activated globally?
e
The Spring extensions do. Extensions that you normally activate in a spec can be done the same way still.
thank you color 1
v
@Emil Kantis when you have a moment can you share an example please? I've added the following project config
Copy code
object KotestConfig : AbstractProjectConfig() {
    override fun extensions(): List<Extension> = listOf(SpringExtension)
}
but whenever I set either
Copy code
kotest.framework.discovery.jar.scan.disable=true
or
Copy code
kotest.framework.classpath.scanning.autoscan.disable=true
all tests using SpringExtension fail to instantiate.
e
v
I did. I have
kotest.framework.config.fqn=com.hellofresh.rms.processors.KotestConfig
in my kotest.properties.
If you’re using constructor injection for the tests
v
Thank you! I had missed that.
e
All good now?
v
Yes. Thank you!
πŸ’― 1