In order to cover some basic features of golang, in this post I will provide a sample of how to write golang tests.

If we want to test a go file:

foo.go:


package main

func PrintSum(a, b int){
  fmt.Printf("%v\n", a+b)
}

We need to create a new file, in the same package labeled:

foo_test.go

Then inside it, we create a function:


func TestPrintSum(t *testing.T){
  PrintSum(1,2)
}

Then open a shell and type:

$ go test

And you should be able to see the test output.