Giter Club home page Giter Club logo

assert's Introduction

assert

Assertions for unit tests in Golang, similar to JUnit.

Usage

In case you use "testing", you can directly call the methods. In case you use a different framework than "testing", you need to reassign the Fail function pointer. Due to a lack of generic exceptions, the assertion methods require a t *testing.T passed. The assertion methods need this to call t.Fail(). Therefore, the possibility of reuse of the assert module for other frameworks is limited.

Differences from JUnit

You cannot make any assumptions whether an assertion stops execution of the current test case. In the default implementation, assertions use t.Fail(), by calling t.Error(). In go testing, this will mark the test case as failed, but the test case still continues. If you map Fail to something else, you may make a test stop instead.

Supported Frameworks

Out of the box, assert supports the following frameworks:

  • "testing"
  • "github.com/DATA-DOG/godog"

assert with "testing"

To use assert with "testing", pass t *testing.T as first argument to the assertion.

Example:

import (
	"github.com/christianhujer/assert"
	"testing"
)

func TestExample(t *testing.T) {
	assert.Equals(t, 23, 42)
}

assert with "godog"

To use assert with "godog", return the error returned by the assertion.

Example:

import (
	"github.com/christianhujer/assert"
)

func iMUSTHaveHotdogs(expectedHotdogsRemaining int) error {
	return assert.Equals(nil, expectedHotdogsRemaining, hotdogs)
}

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.