In this section, we will look at the Spek testing framework (https://spekframework.github.io/spek/docs/latest/#_what_is_spek) for Kotlin. Spek, contrary to other frameworks, such as JUnit, provides a way to describe requirements along with a test script. The fact that tests have passed successfully, doesn't mean that our code works as expected and meets our requirements.
As you can see in the previous example, we should use class and method names to describe a case that we want to test. Using the Spek framework, we can rewrite this example as follows:
object CalculatorSpec: Spek({
given("a calculator") {
val calculator = Calculator()
on("addition") {
val sum = calculator.addition(3, 2)
it("adding 3 and 2 should return 5") {
assertEquals(5, sum)
}
...