-
I want to use the best features of both best test-frameworks: goconvey and httpexpect. But both frameworks use its own print format. Does anybody have example of integrate httpexpect in goconvey. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hi, httpexpect always uses these interfaces to print anything:
You can provide your own implementation using corresponding It's enough to implement just Printer and Reporter, however if you want to reuse default httpexpect printers formatting (CompactPrinter, DebugPrinter, or CurlPrinter), you can implement Logger instead of Printer and pass your logger to one of existing printers. |
Beta Was this translation helpful? Give feedback.
-
Thaks. I'll try and I'll say about results. |
Beta Was this translation helpful? Give feedback.
-
@aleus I am very interested in the results and the setup. Since I also use Convey. Thanks |
Beta Was this translation helpful? Give feedback.
-
At the moment I'm doing the following trick
type ConveyReporter struct {
convey.C
}
// Implements httpexpect.Reporter interface.
func (c ConveyReporter) Errorf(message string, args ...interface{}) {
c.C.So(fmt.Sprintf(message, args...), assertionFails)
}
func assertionFails(actual interface{}, _ ...interface{}) string {
return actual.(string)
}
type ConveyPrinter struct {
convey.C
}
// Request implements Printer.Request.
func (ConveyPrinter) Request(*http.Request) {
// Does nothing.
}
// Response implements Printer.Response.
func (p ConveyPrinter) Response(*http.Response, time.Duration) {
p.C.So(true, convey.ShouldBeTrue)
}
func NewExpect(c convey.C) *Expect {
return WithConfig(Config{
BaseURL: myUrl,
Reporter: ConveyReporter{c},
Printers: []Printer{ConveyPrinter{c}},
})
}
// ...
func TestGetUsers(t *testing.T) {
Convey("GET /users", t, func(c C) {
NewExpect(c).GET("/users").
Expect().
Status(http.StatusBadRequest).
JSON().Schema(ErrorSchema).
Object().ValueEqual("code", ErrRequiredAccessToken)
})
}) As the result I have one success GoConvey assertion for every request that has response and if some httpexpect assertion fails it generates GoConvey failure assertion. @gavv is it possible to dig somehow into httpexpect assertion engine? I want to bind every httpexpect assertion to appropriate GoConvey assertion. Even successful ones, not only failed. |
Beta Was this translation helpful? Give feedback.
-
@tyranron currently there is no single entry point for every assertion. To accomplish that, one need to patch all the code and register every issued assertion in somewhere. I guess we could just extend the Reporter interface with a Success() method and call this method from every check in httpexpect. It would be quite a large patch though the changes would be mechanical. |
Beta Was this translation helpful? Give feedback.
-
It's now possible. See here https://github.com/gavv/httpexpect#customize-assertion-handling |
Beta Was this translation helpful? Give feedback.
At the moment I'm doing the following trick