go: Unit test example

This commit is contained in:
Logen Kain 2017-10-03 00:27:35 -07:00
parent ac7405ce04
commit 778b6dd7ab
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package main
import "fmt"
func main() {
fmt.Println("vim-go")
}
func sum(x, y int) int {
return x + y + 1
}

View File

@ -0,0 +1,14 @@
package main
import "testing"
/* Must be camelcase and start with "Test"
so Testsum will not work. sumTest will not work
*/
func TestSum(t *testing.T) {
total := sum(1, 7)
if total != 8 {
t.Errorf("Sum was incorrect, got: %d, want: %d.", total, 8)
}
}