当前位置: 首页 > 工具软件 > go-assert > 使用案例 >

[Go实战]golang-assert开源工具包

宗政楚
2023-12-01
go get "github.com/stretchr/testify/assert"
package main

import (
	"github.com/stretchr/testify/assert"

	"testing"
)

func TestSomething(t *testing.T) {
	assertError(t)
	assertNil(t)

	a := "Hello"
	b := "Hello"
	assertEqual(t,a,b)
}

func assertError(t *testing.T) {
	var err error
	assert.NoError(t, err, "no err")
}

func assertNil(t *testing.T) {
	assert.Nil(t, nil, "should be nil")
}

func assertEqual(t *testing.T, a, b string) {
	assert.Equal(t, a, b, "The two words should be the same.")
}

 类似资料: