Creating steps

Every step function should accept the StepTest as the first 2 parameters and returns the Context. Here’s an example:

type StepFunc func(gobdd.StepTest, ctx gobdd.Context, var1 int, var2 string)

What’s important to stress - the context is a custom struct, not the built-in interface. To retrieve information from previously executed you should use functions ctx.Get*(0). Replace the * with the type you need. Examples:

If the value does not exist the test will fail.

There’s possibility to pass a default value as well.

ctx.GetFloat32(myFloatValue{}, 123)

If the myFloatValue{} value doesn’t exists the 123 will be returned.


There’s a possibility to define hooks which might be helpful building useful reporting, visualization, etc.

suite := NewSuite(
    WithBeforeStep(func(ctx Context) {
        ctx.Set(time.Time{}, time.Now())
    WithAfterStep(func(ctx Context) {
        start, _ := ctx.Get(time.Time{})
        log.Printf("step took %s", time.Since(start.(time.Time)))

Good practices

Steps should be immutable and only communicate through the context.