elicit

package module
v0.0.0-...-63e20c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2018 License: BSD-2-Clause Imports: 14 Imported by: 0

README

CircleCI Go Report Card Godoc

Elicit

Elicit is a Specification by Example framework for Go inspired by similar frameworks such as Cucumber and Gauge.

Note: Go already has excellent support for testing and documentation in its standard library, so you might not need this framework.

That said, if you're using Go as a general-purpose programming language and find yourself needing close collaboration with non-technical stakeholders, then the skills and knowledge required to use Go's existing tools may be a barrier to this. Elicit provides the ability to write executable specifications in plain English, which then form part of the documentation and regression test suite for the system.

Features and aspirations:

  1. Allows executable specifications to be written in markdown.
  2. Follows Go principles, especially in terms of simplicity.
  3. Uses the Go testing API wherever possible.
  4. Doesn't impose restrictions on repository layout.
  5. Requires minimal configuration and no additional dot files.
  6. Integrates with the go toolchain, go test in particular. No additional tooling is required.

Getting started

  1. If you don't already have one, create a project in your workspace.

  2. Create a specification, following the guidance found in the syntax specification. It's convenient to place these in a folder somewhere, we'll assume ./specs.

  3. Create a test file, e.g. my_test.go. Note the _test.go suffix which is a Go testing convention. You only need one of these because it will run all your specifications as subtests.

    package mypackage
    
    import (
        "github.com/mpwalkerdine/elicit"
        "testing"
    )
    
    func Test(t *testing.T) {
        elicit.New().
            WithSpecsFolder("./specs").
            WithSteps(steps).
            RunTests(t)
    }
    
    var steps = elicit.Steps{}
    
  4. Run go test. All the steps will show as "Pending".

  5. Provide some step implementations (see Steps).

  6. Run go test -v to see a complete report (see Logging for more details on -v and related options).

More Information

The specifications for Elicit contain more details. They also serve as a demonstration of its capabilities, because they are also tests for the framework itself.

  • Transforms: Use arbitrary types as parameters in step implementations.
  • Hooks: Register functions to run at particular points in the test cycle.

Dependencies

Blackfriday is used for markdown parsing.

Documentation

Overview

Package elicit is a native go BDD testing framework using markdown for executable specifications

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context stores test machinery and maintains state between specs/scenarios/steps

func New

func New() *Context

New creates a new elicit context which stores specs, steps and transforms

func (*Context) AfterScenarios

func (ctx *Context) AfterScenarios(hook Hook) *Context

AfterScenarios registers a function to be called after each scenario

func (*Context) AfterSpecs

func (ctx *Context) AfterSpecs(hook Hook) *Context

AfterSpecs registers a function to be called after each spec

func (*Context) AfterSteps

func (ctx *Context) AfterSteps(hook Hook) *Context

AfterSteps registers a function to be called after each step

func (*Context) BeforeScenarios

func (ctx *Context) BeforeScenarios(hook Hook) *Context

BeforeScenarios registers a function to be called before each scenario

func (*Context) BeforeSpecs

func (ctx *Context) BeforeSpecs(hook Hook) *Context

BeforeSpecs registers a function to be called before each spec

func (*Context) BeforeSteps

func (ctx *Context) BeforeSteps(hook Hook) *Context

BeforeSteps registers a function to be called before each step

func (*Context) RunTests

func (ctx *Context) RunTests(ctxT *testing.T) *Context

RunTests runs all the discovered specs as tests

func (*Context) WithSpecsFolder

func (ctx *Context) WithSpecsFolder(path string) *Context

WithSpecsFolder recursively adds the path to the discovery path of specs

func (*Context) WithSteps

func (ctx *Context) WithSteps(steps Steps) *Context

WithSteps registers steps from the supplied map of patterns to functions

func (*Context) WithTransforms

func (ctx *Context) WithTransforms(txs Transforms) *Context

WithTransforms registers step argument transforms from the suppled map of patterns to functions

type Hook

type Hook func()

Hook is a function which can be registered to execute before/after each spec/scenario/step

type Hooks

type Hooks []Hook

Hooks is a slice of Hooks

type Steps

type Steps map[string]interface{}

Steps are used to register step implemenations against regex patterns The key must successfully compile to a regexp.Regexp and the values must be functions obeying the semantics of a step implementation. Step Implementations are of the form: func(t *testing.T, param string) {} The number of additional parameters should match the number of subgroups in the pattern used as a key.

type Table

type Table struct {
	Columns []string
	Rows    []map[string]string
}

Table holds test data from the spec

type TextBlock

type TextBlock struct {
	Language string
	Content  string
}

TextBlock represents a code block from markdown

type Transforms

type Transforms map[string]interface{}

Transforms are used to register functions which can convert strings captured by steps into the types expected by the step implementation. The string is a pattern which captured subgroups must match for the transform to be considered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL