kspec alternatives and similar libraries
Based on the "Tests" category.
Alternatively, view kspec alternatives based on common mentions on social networks and blogs.
-
Kotest
Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing -
kotlin-faker
https://serpro69.github.io/kotlin-faker/ Generate realistically looking fake data such as names, addresses, banking details, and many more, that can be used for testing and data anonymization purposes. -
hikaku
A library that tests if the implementation of a REST-API meets its specification. -
balin
Balin is an automation library for Kotlin. It's basically a Selenium-WebDriver wrapper inspired by Geb. -
SeleniumBuilder
Kotlin DSL for Selenium. Provide a possibility to write tests in Kotlin type-safe builders style -
arbitrater
Arbitrater is a Kotlin library for creating arbitrary instances of classes by reflection for use in testing. In contrast to POJO generators, it supports Kotlin's optional parameters and nullable types. -
aspen
Aspen is a simple test runner for Kotlin that allows you to write tests using your own DSL. -
mock-fuel
JUnit 5 extension to easily test with the http client Fuel for Kotlin
Appwrite - The Open Source Firebase alternative introduces iOS support
Do you think we are missing an alternative of kspec or a related project?
Popular Comparisons
README
(NO LONGER MAINTANED) KSpec -> Spek.
KSpec
Specifications for Kotlin.
Basic Structure
class TheMostAmazingAnimalSpec: KSpec() {
override fun spec() {
describe("the most amazing animal in the universe") {
val animal = GetMostAmazingAnimal()
it("should be a panda") {
assertThat(animal.type, equalTo("panda"))
}
context("not a panda") {
it("nope, not going to accept it") {
assertThat({
assertThat(animal.type, not(equalTo("panda")))
}, thrown(EndOfTheWorldException::class))
}
}
}
}
}
Context
KSpec is heavily inspired by RSpec, Context
is synonymous to RSpec's scopes.
Example
The test method in JUnit and created using it
.
ExampleGroup
Groups similar examples together (they might be testing the same Subject
- more on this later) and is created by using describe
or context
. Be cautious in placing logic code in them as they are eagerly evaluated
Fixtures
KSpec provides before
, beforeEach
, afterEach
and after
callbacks for each context.
Subject
Just like RSpec, KSpec also support subjects.
class TheMostAmazingAnimalSpec: KSpec() {
override fun spec() {
describe("the most amazing animal in the universe") {
subject {
[email protected] GetMostAmazingAnimal();
}
it("should be a panda") {
assertThat(subject.type, equalTo("panda"))
}
context("not a panda") {
it("nope, not going to accept it") {
assertThat({
assertThat(subject.type, not(equalTo("panda")))
}, thrown(EndOfTheWorldException::class))
}
}
}
}
}
Shared Examples
Sometimes it's convenient to reuse examples - like testing a subclass.
class CalculatorSpec: KSpec() {
override fun spec() {
describe(Calculator::class) {
itBehavesLike(calculator())
}
}
companion object {
fun calculator() = sharedExample<Calculator> {
describe("add") {
it("1 + 1 = 2") {
assertThat(subject.add(1, 1), equalTo(2))
}
}
...
}
}
}
class AdvancedCalculatorSpec: KSpec() {
override fun spec() {
describe(AdvancedCalculator::class) {
itBehavesLike(CalculatorSpec.calculator())
}
}
}
Pending
You can write specs in advance, KSpec will ignore them during execution.
class SomeSpec: KSpec() {
override fun spec() {
xdescribe("a pending group") {
it("won't be executed") { }
}
xcontext("another pending group", "some reason")
xit("a pending example") { }
}
}
Focused
KSpec supports focusing execution only on several contexts. Use fdescribe
and fcontext
to create a focused group, and fit
to create a focused example. KSpec will only run focused contexts if there are any, othewise it will run everything.
Tagging
TODO
Filters
This allows to control which contexts to run. It can be configured per spec (by overriding configure
) or by using Shared Configurations.
class SomeSpec: KSpec() {
override fun configure(config: KSpecConfig) {
// config.filter.<filter> = tags
}
}
include
Only include contexts having at least one of the tags
specified.
exclude
Exclude any contexts having at least one of the tags
specified.
matching
Similar to the include filter, the only difference is that if there is no match run everything.
Shared Configurations
Declare shared configurations by extending Configuration
and apply it to a spec via @Configurations
.
class SharedConfiguration: Configuration {
override fun apply(config: KSpecConfig) {
...
}
}
class AnotherConfiguration: Configuration {
override fun apply(config: KSpecConfig) {
...
}
}
// use it
@Configurations(
SharedConfiguration::class,
AnotherConfiguration::class
)
class SomeSpec: KSpec() {
...
}
Usage
Console Runner
TODO
Gradle
Currently you need to use a JUnit4 Runner
to be able to run specs with gradle. Make sure to annotate your test classes with @RunWith(JUnitKSpecRunner::class)
.
repositories {
jcenter()
}
dependencies {
testCompile "io.polymorphicpanda.kspec:kspec-core:<kspec-version>"
testCompile "io.polymorphicpanda.kspec:kspec-junit-runner:<kspec-version>"
}
Development version
Gradle
repositories {
maven {
url "http://oss.jfrog.org/artifactory/oss-snapshot-local/"
}
}