This library allows automatically generate text files with specifications directly from your tests.
I love the Kotlin and Spek framework. This combination allows creating human-readable tests (please take a look into the Kluent assertion library).
I want to get "out of the box" only one thing - it's text specification files (something like in Cucumber).
- Add repository
repositories {
maven {
url = uri("https://maven.pkg.github.com/paslavsky/spec-report")
}
}
- Add dependency
dependencies {
testImplementation 'com.github.paslavsky:spec-report:<version>'
}
- Add repository
<distributionManagement>
<repository>
<id>spec-report</id>
<name>Scec report repository</name>
<url>https://maven.pkg.github.com/paslavsky/spec-report</url>
</repository>
</distributionManagement>
- Add dependency
<dependencies>
<dependency>
<groupId>com.github.paslavsky</groupId>
<artifactId>spec-report</artifactId>
<version>${spec-report.version}</version>
</dependency>
</dependencies>
Please create your abstract class for basic Spek tests, for example:
abstract class MySpek(body: Root.() -> Unit) : Spek({
registerListener(SpecWriter)
// ... <- your custom logic goes here
body(this)
})
or you can use my class com.github.paslavsky.Spec
.
So, your tests will look something like this:
object CalculatorSpec: MySpek({
describe("A calculator") {
val calculator by memoized { Calculator() }
describe("addition") {
it("returns the sum of its arguments") {
assertEquals(3, calculator.add(1, 2))
}
}
}
})
Now, run your tests and look into the build/reports/specs
folder. You should find a new spec file:
A calculator
addition
returns the sum of its arguments
P.S. Please see tests for more examples.
The spec-report
allows some customization. It could be done programmatically or via the spec-report.properties
file.
You can change what you need directly at the com.github.paslavsky.Configuration
object. For example, you can create your abstract spec class:
abstract class MySpek(body: Root.() -> Unit) : Spek({
registerListener(SpecWriter)
Configuration.failed = "FAIL"
Configuration.passed = "PASS"
body(this)
})
At the configuration file, you can define the following properties:
Property | Default | Description |
---|---|---|
failed |
'F' |
Prefix for failed tests |
passed |
' ' |
Prefix for successfully passed tests. |
filePattern |
{name}.spec |
Name pattern for your specification files. At the current moment, we have only one placeholder - {name} . |
specFolder |
./build/reports/specs or ./specs |
Folder name where the library will generate specification files. |
If this helpful library for you and you have any ideas what to add - please welcome to create a new issue or PR.