This recipe will demonstrate the process to write a table-driven test, collect test coverage, and improve it. It will also make use of the github.com/cweill/gotests package to generate tests. If you've been downloading the test code for other chapters, these should look very familiar. Using a combination of this recipe and the previous two, you should be able to achieve 100% test coverage in all cases with some work.
Using table-driven tests to improve coverage
Getting ready
Configure your environment according to these steps:
- Refer to the Getting ready section of the Mocking using the standard library recipe of this chapter.
- Run the go get github.com/cweill/gotests/ command.