Go Testing Testify Assert Require Suite Mock Structs
Definisi
testify adalah library populer yang menambah assert (lanjut meski gagal) dan require (berhenti jika gagal) serta suite untuk mengelompokkan test dengan setup/teardown. Membuat test Go lebih ringkas dari if got != want.
Kapan dipakai
Pakai saat ingin assertion ekspresif tanpa boilerplate t.Errorf. suite berguna bila banyak test butuh state bersama (DB test, fixtures).
Cara kerja
assert vs require
import "github.com/stretchr/testify/assert"
func TestAdd(t *testing.T) {
got := Add(2, 3