Giter VIP home page Giter VIP logo

Gucumber

GoDoc Build Status MIT License

An implementation of Cucumber BDD-style testing for Go.

Installing

$ go get github.com/gucumber/gucumber/cmd/gucumber

Usage

Cucumber tests are made up of plain text ".feature" files and program source "step definitions", which for Gucumber are written in Go.

Features

Put feature files internal/features/ with whatever organization you prefer. For example, you might create internal/features/accounts/login.feature with the following text:

@login
Feature: Login Support

  Scenario: User successfully logs in
    Given I have user/pass "foo" / "bar"
    And they log into the website with user "foo" and password "bar"
    Then the user should be successfully logged in

Step Definitions

Create step definitions to match each step in your feature files. These go in ".go" files in the same internal/features/ directory. We might create internal/features/accounts/step_definitions.go:

package accounts

import (
	. "github.com/gucumber/gucumber"
)

func init() {
	user, pass := "", ""

	Before("@login", func() {
		// runs before every feature or scenario tagged with @login
		generatePassword()
	})

	Given(`^I have user/pass "(.+?)" / "(.+?)"$`, func(u, p string) {
		user, pass = u, p
	})

	// ...

	Then(`^the user should be successfully logged in$`, func() {
		if !userIsLoggedIn() {
			T.Errorf("user should have been logged in")
		}
	})
}

T?

The T value is a testing.T style value that represents the test context for each test. It mostly supports Errorf(fmt, args...), but also supports other convenience methods. See the API documentation for more information.

Running

To run your tests, execute:

$ gucumber

You can also specify the path to features in command line arguments:

$ gucumber path/to/features

You can also filter features and scenarios by tags:

$ gucumber -tags=@login # only run login feature(s)

Or:

$ gucumber -tags=~@slow # ignore all "slow" scenarios

Copyright

This library was written by Loren Segal in 2015. It is licensed for use under the MIT license.

gucumber's Projects

gucumber icon gucumber

An implementation of Cucumber BDD-style testing for Go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.