You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes a test suite might need an assertion that is too specific to be included in the general repository. Not to worry, simply implement a function with the following signature (replace the bracketed parts and string values):
funcshould<do-something>(actualinterface{}, expected...interface{}) string {
if<some-important-condition-is-met(actual, expected)> {
return""// empty string means the assertion passed
}
return"<some descriptive message detailing why the assertion failed...>"
}
Suppose I implemented the following assertion:
funcshouldScareGophersMoreThan(actualinterface{}, expected...interface{}) string {
ifactual=="BOO!"&&expected[0] =="boo" {
return""
}
return"Ha! You'll have to get a lot friendlier with the capslock if you want to scare a gopher!"
}
I can then make use of the assertion function when calling the So() method in the tests:
Convey("All caps always makes text more meaningful", func() {
So("BOO!", shouldScareGophersMoreThan, "boo")
})