-
-
Save ivan-marquez/21ff211e89e5a69918733a4f8f247b76 to your computer and use it in GitHub Desktop.
Golang unit test for panic scenario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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