Spek - xgouchet/Elmyr GitHub Wiki
The spek
module provides integration with the Spek Test Framework.
spekForge
When writing a Spek test, you can create a root Forge
instance, that will allow you to forge random test inputs.
class FooSpek : Spek({
val forge = spekForge()
// …
})
Reproducible tests
Whenever a test fails, or just to reproduce the same test exactly, you can use the spekForge
's seeds
parameter.
Seeds will be assigned based on the qualified name of a test or group.
class FooSpek : Spek({
val forge = spekForge(
seeds = mapOf(
"FooSpek/Foo feature/bar/baz" to 0x1337L
)
)
describe("Foo feature") {
describe("bar") {
it("baz") {
val i = forge.anInt()
// …
}
}
}
})
Custom Factories
Chances are, you'll need to forge more than primitives or Strings. To do so you'll need to use Factories.
A simple way to provide that to the extension is to use the spekForge
's seeds
parameter with a custom configurator instance.
class FooSpek : Spek({
val forge = spekForge(
configurator = MyConfigurator()
)
// …
})
class MyConfigurator : ForgeConfigurator {
override fun configure(forge: Forge) {
forge.addFactory(Foo::class.java, FooFactory())
forge.addFactory(Bar::class.java, BarFactory())
}
}