Categorygithub.com/allisson/go-assert
modulepackage
0.2.0
Repository: https://github.com/allisson/go-assert.git
Documentation: pkg.go.dev

# README

go-assert

Build Status Go Report Card go.dev reference

Simple asserts to use with golang testing.

Quickstart

// file test_test.go
package test

import (
    "testing"

    assert "github.com/allisson/go-assert"
)

func TestExamples(t *testing.T) {
    assert.Equal(t, 1, 1)
    assert.NotEqual(t, 1, 2)
    assert.Nil(t, nil)
    assert.NotNil(t, 1)
}
go test -v
=== RUN   TestExamples
--- PASS: TestExamples (0.00s)
PASS
// file test_test.go
package test

import (
    "testing"

    assert "github.com/allisson/go-assert"
)

func TestExamples(t *testing.T) {
    assert.Equal(t, 1, 2)
}
go test -v
=== RUN   TestExamples
--- FAIL: TestExamples (0.00s)
    test_test.go:10: assertion_type=Equal, expected_value=1, expected_type=int, current_value=2, current_type=int
FAIL
exit status 1

# Functions

Equal compares two values using reflect.DeepEqual and fails if not equals.
Nil fails if value is not nil.
NotEqual compares two values using reflect.DeepEqual and fails if equals.
NotNil fails is value is nil.