wstest alternatives and similar packages
Based on the "Testing Frameworks" category.
Alternatively, view wstest alternatives based on common mentions on social networks and blogs.
-
gnomock
integration testing with real dependencies (database, cache, even Kubernetes or AWS) running in Docker, without mocks. -
gotest.tools
A collection of packages to augment the go testing package and support common patterns. -
embedded-postgres
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test. -
gospecify
This provides a BDD syntax for testing your Go code. It should be familiar to anybody who has used libraries such as rspec. -
assert
Basic Assertion Library used along side native go testing, with building blocks for custom assertions -
Hamcrest
fluent framework for declarative Matcher objects that, when applied to input values, produce self-describing results. -
gosuite
Brings lightweight test suites with setup/teardown facilities to testing by leveraging Go1.7's Subtests
Get performance insights in less than 4 minutes
Do you think we are missing an alternative of wstest or a related project?
Popular Comparisons
README
wstest
A websocket client for unit-testing a websocket server
The gorilla organization provides full featured websocket implementation that the standard library lacks.
The standard library provides a httptest.ResponseRecorder
struct that test
an http.Handler
without ListenAndServe
, but is helpless when the connection is being hijacked
by an http upgrader. As for testing websockets, it has the httptest.NewServer
that actually
listens on a socket on an arbitrary port.
This package provides a NewDialer function to test just the http.Handler
that upgrades
the connection to a websocket session. It runs the handler function in a goroutine
without listening on any port. The returned websocket.Dialer
then can be used to dial and communicate
with the given handler.
Get
go get -u github.com/posener/wstest
Examples
See the [example test](./example_test.go).
An example how to modify a test function from using
httptest.Server
to use wstest.NewDialer
function.
func TestHandler(t *testing.T) {
var err error
h := &myHandler{}
- s := httptest.NewServer(h)
- defer s.Close()
- d := websocket.Dialer{}
+ d := wstest.NewDialer(h)
- c, resp, err := d.Dial("ws://" + s.Listener.Addr().String() + "/ws", nil)
+ c, resp, err := d.Dial("ws://" + "whatever" + "/ws", nil)
if err != nil {
t.Fatal(err)
}
if got, want := resp.StatusCode, http.StatusSwitchingProtocols; got != want {
t.Errorf("resp.StatusCode = %q, want %q", got, want)
}
err = c.WriteJSON("test")
if err != nil {
t.Fatal(err)
}
}