Coder Social home page Coder Social logo

is's Introduction

is GoDoc Build Status

Is provides a quick, clean and simple framework for writing Go tests.

Installation

To install, simply execute:

go get github.com/tylerb/is

Vendoring

Vendoring is recommended, as this library can change from time to time. The last change was updating it to use the new Helper() method in the 1.9 testing framework.

Check out the official Go dependency manager, dep. Alternatively, I also like glide.

Usage

Using Is is simple:

func TestSomething(t *testing.T) {
	is := is.New(t)

	expected := 10
	result, _ := awesomeFunction()
	is.Equal(expected,result)
}

If you'd like a bit more information when a test fails, you may use the Msg() method:

func TestSomething(t *testing.T) {
	is := is.New(t)

	expected := 10
	result, details := awesomeFunction()
	is.Msg("result details: %s", details).Equal(expected,result)
}

By default, Is fails and stops the test immediately. If you prefer to run multiple assertions to see them all fail at once, use the Lax method:

func TestSomething(t *testing.T) {
	is := is.New(t).Lax()

	is.Equal(1,someFunc()) // if this fails, a message is printed and the test continues
	is.Equal(2,someOtherFunc()) // if this fails, a message is printed and the test continues

If you are using a relaxed instance of Is, you can switch it back to strict mode with Strict. This is useful when an assertion must be correct, or subsequent calls will panic:

func TestSomething(t *testing.T) {
	is := is.New(t).Lax()

	results := someFunc()
	is.Strict().Equal(len(results),3) // if this fails, a message is printed and testing stops
	is.Equal(results[0],1) // if this fails, a message is printed and testing continues
	is.Equal(results[1],2)
	is.Equal(results[2],3)

Strict mode, in this case, applies only to the line on which it is invoked, as we don't overwrite our copy of the is variable.

Contributing

If you would like to contribute, please:

  1. Create a GitHub issue regarding the contribution. Features and bugs should be discussed beforehand.
  2. Fork the repository.
  3. Create a pull request with your solution. This pull request should reference and close the issues (Fix #2).

All pull requests should:

  1. Pass gometalinter -t . with no warnings.
  2. Be go fmt formatted.

is's People

Contributors

tylerb avatar kalafut avatar tylerstillwater avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar Jason Deutsch avatar  avatar

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.