O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works…

Execute a go test from the command line as follows:

$ go test websocket-server_test.go websocket-server.gook  command-line-arguments 0.048s

It will give us the response ok, which means the test compiled and executed successfully.

Let’s see how it looks when a Go test fails. Change the expected output in the assert statement to something else. In the following hello has been changed to hi:

...assert.Equal(t, "hi", message.Message, "they should be equal")...

Execute the test again by running the go test command:

$ go test websocket-server_test.go websocket-server.go

It will give us the failure response along with the error trace as shown in the following screenshot:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required