From 778b6dd7ab1f3b0b9378bc8f428c61fb182cd70e Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Tue, 3 Oct 2017 00:27:35 -0700 Subject: [PATCH] go: Unit test example --- go/unit_test_example/main.go | 11 +++++++++++ go/unit_test_example/main_test.go | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 go/unit_test_example/main.go create mode 100644 go/unit_test_example/main_test.go 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) + } +}