Steps

A step is where interaction with your system happen, it:

  • has a name

  • can be retried

  • has an execution

  • has a list of assertions

step(
    name = "a name a step has",
    retry = 10.times byIntervalsOf 200.ms, // if assertions of step fail, step will be retried 10 times by intervals of 200 ms before really failing. Useful if you have asynchonous stuff going on on your backends.
) {
    // here goes the definition of the execution
} assertThat {
    // here goes list of assertions
}

Available Steps

Redis

Cadence

Create your own step

You need custom steps not provided by Kest? Two options:

  • Use generic step step

    step(name = "name of my step") {
    
        // execute your need here
        1+1
    
    } assertThat { stepResult ->
    
        stepResult isEqualTo 2
    
    }
  • Create your own one

Nested scenario

If you want to group some steps together to make your scenario clearer you may use a particular step that allows that

nestedScenario("group steps") {
    step(name = "step1") { /*...*/ }
    step(name = "step2") { /*...*/ }
    step(name = "step3") { /*...*/ }
}

Reuse result of one step in another one

When you create a step, you call a function that will return a StepResult
It’s on that StepResult that make assertions.
It’s also on that StepResult that you can retrieve the result of the step.

val step1: StepResult<Int> = step { 1+1 } assertThat { it isEqualTo 2 }

val step2: StepResult<Double> = step { step1() + 1.5 } assertThat { it isEqualTo 3.5 }

step { step2.invoke().toString() } assertThat { it isEqualTo "3.5" }

As you can see on the example, to get the result of a step you may invoke it.

you may use the result of a step only in the execution of another step, if you try to invoke it outside an execution then the step will probably not have been played yet so no result will be available.

Special case of a nestedScenario

nestedScenario step is a particular step that does not return any result by default.
It is still possible to return a result from a nestedScenario

val step1 = nestedScenario<Double> {

    val step11: StepResult<Int> = step { 1+1 } assertThat { it isEqualTo 2 }

    val step12: StepResult<Double> = step { step11() + 1.5 } assertThat { it isEqualTo 3.5 }

    returns { step12() }
}

step { step1() + 4 } assertThat { it isEqualTo 7.5 }

Transform the result of a step

You may transform a result of a step so that later steps reusing the result will reuse transformed result instead of initial one

val step1 = step { 1 + 1 } mapResultTo { it * 1.0 } assertThat { it isEqualTo 2 }

step { step1() * 3 } assertThat { it isEqualTo 18.0 }

Here step1 result was transformed from an Int to a Double
Even though in assertions of step 1 the result is still an Int: Assertions are always done on initial result, not transformed one.
Then when second step invoked step1 result it got a Double

Take care, when you use mapResultTo it will not transform the result for the assertions of the step, assertions are always done on step initial result.
Moreover, mapResultTo lambda will only be executed when the result of its step will be invoked: if result of that step is never invoked, then mapResultTo lambda will never be executed.