assert

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

README

Assert for Go 1.18+ test assertions

Install

go get github.com/weiwenchen2022/assert

Usage

package main

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

func greet(name string) (string, int) {
    greeting := fmt.Sprintf("Hello %s", name)

    // Return the greeting and its length (in bytes).
    return greeting, len(greeting)
}

func TestGreet(t *testing.T) {
    greeting, greetingLength := greet("Alice")

    assert.Equal(t, "Hello Alice", greeting, "greeting:")
    assert.Equal(t, 11, greetingLength, "greetingLength:")
}

Reference

GoDoc: https://godoc.org/github.com/weiwenchen2022/assert

Documentation

Overview

Package assert defines helper functions for test assertions.

Using helpers for your test assertions can help to:

  • Make your test functions clean and clear;
  • Keep test failure messages consistent;
  • And reduce the potential for errors in your code due to typos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T comparable](tb testing.TB, expected, actual T, format string, args ...any)

func Panic

func Panic(tb testing.TB, fn func(), wantPanic bool, format string, args ...any)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL