Skip to content

Instantly share code, notes, and snippets.

@benjic
Created September 28, 2016 02:14
Show Gist options
  • Save benjic/956cc4b7bd50d4b5f7dc229b73a7b1ae to your computer and use it in GitHub Desktop.
Save benjic/956cc4b7bd50d4b5f7dc229b73a7b1ae to your computer and use it in GitHub Desktop.
package add
func Add(a, b int) int {
return a + b
}
package add
import "testing"
func TestAdd(t *testing.T) {
t.Run("should add 1 and 1", func(t *testing.T) {
got := Add(1, 1)
if got != 2 {
t.Error("Did not get right sum")
}
})
t.Run("should add 1 and 2", func(t *testing.T) {
got := Add(1, 2)
if got != 3 {
t.Error("Did not get right sum")
}
})
}
@benjic
Copy link
Author

benjic commented Sep 28, 2016

I am currently running go 1.7.1.

> go version
go version go1.7.1 linux/amd64

Running the test functions as expected.

> go test
PASS
ok      _/tmp/mock_tests    0.002s

Running the tests with the verbose flag works as expected.

> go test -v 
=== RUN   TestAdd
=== RUN   TestAdd/should_add_1_and_1
=== RUN   TestAdd/should_add_1_and_2
--- PASS: TestAdd (0.00s)
    --- PASS: TestAdd/should_add_1_and_1 (0.00s)
    --- PASS: TestAdd/should_add_1_and_2 (0.00s)
PASS
ok      _/tmp/mock_tests    0.001s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment