go-hit alternatives and similar packages
Based on the "Testing Frameworks" category.
Alternatively, view go-hit alternatives based on common mentions on social networks and blogs.
-
Testify
A toolkit with common assertions and mocks that plays nicely with the standard library -
GoConvey
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go. -
gnomock
Test your code without writing mocks with ephemeral Docker containers ๐ฆ Setup popular services with just a couple lines of code โฑ๏ธ No bash, no yaml, only code ๐ป -
go-vcr
Record and replay your HTTP interactions for fast, deterministic and accurate tests -
testfixtures
Ruby on Rails like test fixtures for Go. Write tests against a real database -
embedded-postgres
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test -
gotest.tools
A collection of packages to augment the go testing package and support common patterns. -
testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! ๐ -
go-testdeep
Extremely flexible golang deep comparison, extends the go testing package, tests HTTP APIs and provides tests suite -
go-carpet
go-carpet - show test coverage in terminal for Go source files -
dbcleaner
Clean database for testing, inspired by database_cleaner for Ruby -
GoSpec
Testing framework for Go. Allows writing self-documenting tests/specifications, and executes them concurrently and safely isolated. [UNMAINTAINED] -
jsonassert
A Go test assertion library for verifying that two representations of JSON are semantically equal -
testcase
testcase is an opinionated testing framework to support test driven design. -
assert
:exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions -
gogiven
gogiven - BDD testing framework for go that generates readable output directly from source code -
schema
Quick and easy expression matching for JSON schemas used in requests and responses -
gosuite
Test suites support for standard Go1.7 "testing" by leveraging Subtests feature -
testsql
Generate test data from SQL files before testing and clear it after finished.
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of go-hit or a related project?
Popular Comparisons
README
go-hit
[
](#)
hit is an http integration test framework written in golang.
It is designed to be flexible as possible, but to keep a simple to use interface for developers.
So lets get started!
go get -u github.com/Eun/go-hit
```go //ignore package main
import ( "net/http" . "github.com/Eun/go-hit" )
func main() { MustDo( Description("Post to httpbin.org"), Get("https://httpbin.org/post"), Expect().Status().Equal(http.StatusMethodNotAllowed), Expect().Body().String().Contains("Method Not Allowed"), ) }
Or use the `Test()` function:
```go //ignore
package main_test
import (
"testing"
"net/http"
. "github.com/Eun/go-hit"
)
func TestHttpBin(t *testing.T) {
Test(t,
Description("Post to httpbin.org"),
Get("https://httpbin.org/post"),
Expect().Status().Equal(http.StatusMethodNotAllowed),
Expect().Body().String().Contains("Method Not Allowed"),
)
}
Expect, Expect, Expect, ....
MustDo(
Get("https://httpbin.org/post"),
Expect().Status().Equal(http.StatusMethodNotAllowed),
Expect().Headers("Content-Type").NotEmpty(),
Expect().Body().String().Contains("Method Not Allowed"),
)
Sending Data
MustDo(
Post("https://httpbin.org/post"),
Send().Body().String("Hello HttpBin"),
Expect().Status().Equal(http.StatusOK),
Expect().Body().String().Contains("Hello HttpBin"),
)
Sending And Expecting JSON
MustDo(
Post("https://httpbin.org/post"),
Send().Headers("Content-Type").Add("application/json"),
Send().Body().JSON(map[string][]string{"Foo": []string{"Bar", "Baz"}}),
Expect().Status().Equal(http.StatusOK),
Expect().Body().JSON().JQ(".json.Foo[1]").Equal("Baz"),
)
Storing Data From The Response
var name string
var roles []string
MustDo(
Post("https://httpbin.org/post"),
Send().Headers("Content-Type").Add("application/json"),
Send().Body().JSON(map[string]interface{}{"Name": "Joe", "Roles": []string{"Admin", "Developer"}}),
Expect().Status().Equal(http.StatusOK),
Store().Response().Body().JSON().JQ(".json.Name").In(&name),
Store().Response().Body().JSON().JQ(".json.Roles").In(&roles),
)
fmt.Printf("%s has %d roles\n", name, len(roles))
Problems? Debug
!
MustDo(
Post("https://httpbin.org/post"),
Debug(),
Debug().Response().Body(),
)
Handling Errors
It is possible to handle errors in a custom way. ```go //ignore func login(username, password string) error { err := Do( Get("https://httpbin.org/basic-auth/joe/secret"), Send().Headers("Authorization").Add("Basic " + base64.StdEncoding.EncodeToString([]byte(username + ":" + password))), Expect().Status().Equal(http.StatusOK), ) var hitError *Error if errors.As(err, &hitError) { if hitError.FailingStepIs(Expect().Status().Equal(http.StatusOK)) { return errors.New("login failed") } } return err }
## Build the request url manually
```go
MustDo(
Request().Method(http.MethodPost),
Request().URL().Scheme("https"),
Request().URL().Host("httpbin.org"),
Request().URL().Path("/post"),
Request().URL().Query("page").Add(1),
Expect().Status().Equal(200),
Send().Body().String("Hello World"),
Expect().Body().String().Contains("Hello"),
)
Twisted!
Although the following is hard to read it is possible to do!
MustDo(
Post("https://httpbin.org/post"),
Expect().Status().Equal(200),
Send().Body().String("Hello World"),
Expect().Body().String().Contains("Hello"),
)
Custom Send And Expects
MustDo(
Get("https://httpbin.org/get"),
Send().Custom(func(hit Hit) error {
hit.Request().Body().SetStringf("Hello %s", "World")
return nil
}),
Expect().Custom(func(hit Hit) error {
if len(hit.Response().Body().MustString()) <= 0 {
return errors.New("expected the body to be not empty")
}
return nil
}),
Custom(AfterExpectStep, func(Hit) error {
fmt.Println("everything done")
return nil
}),
)
Templates / Multiuse
template := CombineSteps(
Post("https://httpbin.org/post"),
Send().Headers("Content-Type").Add("application/json"),
Expect().Headers("Content-Type").Equal("application/json"),
)
MustDo(
template,
Send().Body().JSON("Hello World"),
)
MustDo(
template,
Send().Body().JSON("Hello Universe"),
)
Clean Previous Steps
Sometimes it is necessary to remove some steps that were added before.
template := CombineSteps(
Get("https://httpbin.org/basic-auth/joe/secret"),
Expect().Status().Equal(http.StatusOK),
)
MustDo(
Description("login with correct credentials"),
template,
Send().Headers("Authorization").Add("Basic " + base64.StdEncoding.EncodeToString([]byte("joe:secret"))),
)
Test(t,
Description("login with incorrect credentials"),
template,
Clear().Expect().Status(),
Expect().Status().Equal(http.StatusUnauthorized),
Send().Headers("Authorization").Add("Basic " + base64.StdEncoding.EncodeToString([]byte("joe:joe"))),
)
More examples can be found in the examples directory
Changelog
0.5.0
- Rehaul the api, make things more explicit
- Fix some issues
Store()
functionality- Generate
Clear()
paths - Infinite
JQ()
functionality - Test
README.md
and documentation parts
0.4.0
- Fixed a double run bug in
CombineSteps
(#3) - Better
Clear
functionality, you can now clear any previous step by prependingClear()
, eg. ```go //ignore Do( Get("https://example.com"), Expect().Body("Hello World"), Clear().Expect(), // remove all previous Expect() steps // Clear().Expect().Body("Hello World"), // remove only the Expect().Body("Hello World") step )
// also works for CombineSteps
Do(
Post("https://example.com"),
CombineSteps(
Send().Body().String("Hello World"),
Expect().Body("Hello World"),
),
Clear().Expect(),
)
* Simplified `Expect().Header()` use, no more `Expect().Headers()`,
everything can now be done in the `Expect().Header()` function.
* More documentation and examples
* `hit.Do` and `hit.MustDo` for inline steps.
* Removal of inline steps (use `hit.Do` and `hit.MustDo`)
```go //ignore
Do(
Get("https://example.com"),
Expect().Custon(func (hit Hit) {
// Expect("Hello World") is invalid now
// you must use MustDo() or Do()
hit.MustDo(
Expect("Hello World"),
)
}),
)
hit.InsertSteps
to insert steps during runtime