go: Unit test example
This commit is contained in:
parent
ac7405ce04
commit
778b6dd7ab
11
go/unit_test_example/main.go
Normal file
11
go/unit_test_example/main.go
Normal 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
|
||||
}
|
14
go/unit_test_example/main_test.go
Normal file
14
go/unit_test_example/main_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user