github.com/lovung/GoCleanArchitecture@v0.0.0-20210302152432-50d91fd29f9f/pkg/testhelper/panic.go (about) 1 package testhelper 2 3 import "testing" 4 5 // ShouldPanic helps to test the panic case 6 // Refer: https://gist.github.com/wrunk/4afea3d85cc9feb7fd8fcef5a8a98b5e 7 func ShouldPanic(t *testing.T, f func()) { 8 defer func() { recover() }() 9 f() 10 t.Errorf("should have panicked") 11 }