Add
function to try things out. Create a test file called adder_test.go
and write this code.package
per directory, make sure that your files are organised separately. Here is a good explanation on this.​%d
as our format strings rather than %q
. That's because we want it to print an integer rather than a string.integers
, as the name suggests this will group functions for working with integers such as Add
.go test
./adder_test.go:6:9: undefined: Add
(x int, y int)
you can shorten it to (x, y int)
.adder_test.go:10: expected '4' but got '0'
Add
function will add the parameters. You can refer this wiki for more details._test.go
files. Add the following ExampleAdd
function to the adder_test.go
file.import "fmt"
in adder_test.go
. It is strongly recommended you research how to have these kind of errors fixed for you automatically in whatever editor you are using.)// Output: 6
. Although the function will be compiled, it won't be executed.godoc
, making your code even more accessible.godoc -http=:6060
and navigate to http://localhost:6060/pkg/