This recipe will demonstrate the process of how 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.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter9/coverage, and navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter9/coverage
You should see a file calledgo.modthat contains the following:
...