testequal

package
v0.0.0-...-50b27ac Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 0 Imported by: 0

README

testequal

В этой задаче нужно реализовать 4 test helper'а, аналогичных функциям из testify:

func AssertEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) bool
func AssertNotEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) bool
func RequireEqual(t T, expected, actual interface{}, msgAndArgs ...interface{})
func RequireNotEqual(t T, expected, actual interface{}, msgAndArgs ...interface{})

Функции проверяют на равенство expected и actual и завершают тест, если проверка не прошла. msgAndArgs попадают в описание ошибки через fmt.Sprintf.

Пример использования:

func TestMath(t *testing.T) {
	AssertEqual(t, 1, 2, "1 == 2")
}

вывод теста:

=== RUN   TestMath
--- FAIL: TestMath (0.00s)
    math_test.go:43: not equal:
        expected: 1
        actual  : 2
        message : 1 == 2
FAIL
FAIL    gitlab.com/slon/shad-go/testequal 0.003s
FAIL

В отличие от testify реализация ограничивает набор типов, с которыми умеет работать:

  1. Целые числа: int, int64 и др (см. тесты)
  2. string
  3. map[string]string
  4. []int
  5. []byte

Ссылки

  1. testing.T: https://golang.org/pkg/testing/#T
  2. type assertions: https://golang.org/doc/effective_go.html#interface_conversions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) bool

AssertEqual checks that expected and actual are equal.

Marks caller function as having failed but continues execution.

Returns true iff arguments are equal.

func AssertNotEqual

func AssertNotEqual(t T, expected, actual interface{}, msgAndArgs ...interface{}) bool

AssertNotEqual checks that expected and actual are not equal.

Marks caller function as having failed but continues execution.

Returns true iff arguments are not equal.

func RequireEqual

func RequireEqual(t T, expected, actual interface{}, msgAndArgs ...interface{})

RequireEqual does the same as AssertEqual but fails caller test immediately.

func RequireNotEqual

func RequireNotEqual(t T, expected, actual interface{}, msgAndArgs ...interface{})

RequireNotEqual does the same as AssertNotEqual but fails caller test immediately.

Types

type T

type T interface {
	Errorf(format string, args ...interface{})
	Helper()
	FailNow()
}

T is an interface wrapper for *testing.T that contains only a small subset of methods.

Jump to

Keyboard shortcuts

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