You can’t think of deploying your application to production without testing it. Neither you can manage a large codebase with confidence without it. Let us go through some basics of unit testing in golang. This post is structured in the following manner: unit testing basics in golang (jump) inbuilt code coverage command understanding subtests and helper function (jump) Travis CI integration (jump) running test against multiple version of go Unit Testing in golang Before I start, I must say that do not test code, test the behavior.
Me Before 1 2 3 4 5 6 7 8 9 10 11 12 FROMgolang:alpineWORKDIR/go/src/github.com/santosh/qagineCOPY . .RUN go get -dRUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app .EXPOSE8080CMD ["./app"] Me building the image. $ docker build -t sntshk/qagine . Sending build context to Docker daemon 259.6kB Step 1/7 : FROM golang:alpine ---> 760fdda71c8f Step 2/7 : WORKDIR /go/src/github.com/santosh/qagine ---> Running in e2cf75dd1655 Removing intermediate container e2cf75dd1655 ---> 8b4955b2e885 Step 3/7 : COPY .