github.com/vizor-games/golang-unittest
go get github.com/vizor-games/golang-unittest

github.com/vizor-games/golang-unittest

Two simple functions for soft unit test assertions in Go.

by vizor-games

v0.0.0-20181204092023-63cfe0386347 (see all)License:MIT
go get github.com/vizor-games/golang-unittest
Readme

golang asserts and checks

Build Status

Two set of assert and check functions for hard and soft unit test assertions in Go. The golang creators reject to create own testing framework, see Go FAQ about testing framework.

Inspired by:

Improvements:

  • check functions
  • frendlier error messages, including correct code line from tests
  • In function for strings
  • Error, NilError functions for functions that returns more than one parameter
  • NilErr - short way to check no errors

The check functions are soft assertions. Failing tests will only be reported to the console via t.Errorf(). The assert functions are hard assertions. Failing tests will be reported to the console via t.Failf() and skip the current test execution.

Check equal

import "https://github.com/vizor-games/golang-unittest/check"

type Person struct {
    name string
    age  int
}

var paul = Person{
    name: "Paul",
    age:  32,
}

paul2 := paul

func TestEqual(t *testing.T) {
    check.Equal(t, paul, paul2, "Paul equals Paul")
}

Assert not equal

var peter = Person{
    name: "Peter",
    age:  21,
}

func TestNotEqual(t *testing.T) {
    assert.NotEqual(t, paul, peter, "Paul does not equal Peter")

Functions that returns additional error value

Use assert.J or check.J to convert args... to []interface{}:

func TestError(t *testing.T) {
    // "err is not nil for unexist file"
    assert.Error(t, assert.J(os.Open("unexist.file")))
}

Installation

New way:

vgo get github.com/vizor-games/golang-unittest

Old way:

go get github.com/vizor-games/golang-unittest

Run tests

go test -v  # -v - verbose
go test ./assert
go test ./check

License

This project is distributed under the MIT license.

GitHub Stars

11

LAST COMMIT

3yrs ago

MAINTAINERS

0

CONTRIBUTORS

3

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20181204092023-63cfe0386347
2yrs ago
No alternatives found
No tutorials found
Add a tutorial