How it works...

This recipe demonstrates how to wire the goconvey command into your tests. The Convey keyword basically replaces t.Run and adds additional labels in the goconvey web UI, but it behaves slightly differently. If you have nested Convey blocks, they're always re-executed in order, as follows:

Convey("Outer loop", t, func(){
a := 1
Convey("Inner loop", t, func() {
a = 2
})
Convey ("Inner loop2", t, func(){
fmt.Println(a)
})
})

The preceding code, using the goconvey command, will print 1. If we had used the built-in t.Run instead, it would print 2 instead. In other words, Go t.Run tests are run sequentially and are never repeated. This behavior can be useful for putting the setup code into outer Convey blocks, but it's important to remember this distinction if you have to work with both.

When using Convey assertions, there are check marks on successes in the web UI and in additional stats. It can also reduce the size of checks to a single line, and it's even possible to create custom assertions.

If you leave the goconvey web interface up and turn on notifications, as you save your code, tests will automatically be run and you'll receive notifications on any increase or decrease in coverage, as well as when your build fails.

All three tools assertions, the test runner, and the web UI can be used independently or together.

The gocov tool can be useful when working toward higher test coverage. It can quickly identify functions that are lacking in coverage and help you to dive deep into your coverage report. In addition, gocov can be used to generate an alternate HTML report that is shipped with the Go code by using the github.com/matm/gocov-html package.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.71.237