Skip to content

Instantly share code, notes, and snippets.

@ivan-marquez
Forked from wrunk/user_test.go
Created September 8, 2019 01:01
Show Gist options
  • Save ivan-marquez/21ff211e89e5a69918733a4f8f247b76 to your computer and use it in GitHub Desktop.
Save ivan-marquez/21ff211e89e5a69918733a4f8f247b76 to your computer and use it in GitHub Desktop.
Golang unit test for panic scenario
func TestUserFail(t *testing.T) {
func() {
defer func() {
if r := recover(); r == nil {
t.Errorf("TestUserFail should have panicked!")
}
}()
// This function should cause a panic
CreateUser(12, "hello")
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment