Create custom asserts
masterCUTE allows implementing custom assertions at three different levels of complexity:
1. Base Asserts
Simple functions that return an error if the assertion fails. Use these for standard logic.
AssertBody func(body []byte) errorAssertHeaders func(headers http.Header) errorAssertResponse func(response *http.Response) error
2. T Asserts (Allure & Testing.TB integration)
These allow you to use cute.T to log information to Allure, create steps, and use require style assertions.
AssertBodyT func(t cute.T, body []byte) errorAssertHeadersT func(t cute.T, headers http.Header) errorAssertResponseT func(t cute.T, response *http.Response) error
3. Custom Assert Errors
To create detailed, pretty errors in Allure, use the cute/errors package:
errors.NewAssertError(name, message, params, ...): Creates a structured assertion error.errors.NewOptionalError(err): Creates an error that causes the step to fail but allows the overall test to pass.
// Example of a Base Assert
func customAssertBody() cute.AssertBody {
return func(bytes []byte) error {
if len(bytes) == 0 {
return errors.New("response body is empty")
}
return nil
}
}
// Example of a T Assert with Allure steps
func customAssertBodySuite() cute.AssertBodyT {
return func(t cute.T, bytes []byte) error {
step := allure.NewSimpleStep("Custom assert step")
defer func() {
t.Step(step)
}()
if len(bytes) == 0 {
step.Status = allure.Failed
step.Attachment(allure.NewAttachment("Error", allure.Text, []byte("response body is empty")))
return nil
}
return nil
}
}