diff --git a/go/unit_test_example/main.go b/go/unit_test_example/main.go new file mode 100644 index 0000000..54b9dab --- /dev/null +++ b/go/unit_test_example/main.go @@ -0,0 +1,11 @@ +package main + +import "fmt" + +func main() { + fmt.Println("vim-go") +} + +func sum(x, y int) int { + return x + y + 1 +} diff --git a/go/unit_test_example/main_test.go b/go/unit_test_example/main_test.go new file mode 100644 index 0000000..7afd0ae --- /dev/null +++ b/go/unit_test_example/main_test.go @@ -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) + } +}