$ brew install golang
$ export GOPATH="$HOME/go"
$ export GOBIN="$GOPATH/bin"
$ export PATH="$GOBIN:$PATH"
$ mkdir -p ~/go/src/github.com/spilth/ogay
$ cd ~/go/src/github.com/spilth/ogay
$ touch ogay_test.go
Following https://golang.org/pkg/testing/
package ogay
import "testing"
func TestWordsStartingWithAVowel(t *testing.T) {
result := TranslateWord("apple")
if result != "appleway" {
t.Errorf("apple translated to `%s`, not `appleway`", result)
}
}
package ogay
func TranslateWord(englishWord string) string {
return englishWord + "way"
}
PASS
ok github.com/spilth/ogay 0.006s
--- FAIL: TestWordsStartingWithAVowel (0.00s)
ogay_test.go:9: apple translated to `appleway`, not `appleways`
FAIL
exit status 1
FAIL github.com/spilth/ogay 0.006s
Using Testify
$ go get github.com/stretchr/testify
package ogay
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWordsStartingWithAVowel(t *testing.T) {
result := TranslateWord("apple")
assert.Equal(t, "appleways", result)
}
PASS
ok github.com/spilth/ogay 0.014s
--- FAIL: TestWordsStartingWithAVowel (0.00s)
ogay_test.go:11:
Error Trace: ogay_test.go:11
Error: Not equal:
expected: "appleways"
actual : "appleway"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-appleways
+appleway
Test: TestWordsStartingWithAVowel
FAIL
exit status 1
FAIL github.com/spilth/ogay 0.013s
Using Ginkgo
$ go get github.com/onsi/ginkgo/ginkgo
$ go get github.com/onsi/gomega/...
$ ginkgo bootstrap
$ rm ogay_test.go
$ ginkgo generate ogay # generates ogay_test.go
package ogay_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spilth/ogay"
)
var _ = Describe("Ogay", func() {
Describe("Translating words", func() {
Context("Words starting with a vowel", func() {
It("translated them correctly", func() {
Expect(ogay.TranslateWord("apple")).To(Equal("appleways"))
})
})
})
})
Running Suite: Ogay Suite
=========================
Random Seed: 1533304301
Will run 1 of 1 specs
•
Ran 1 of 1 Specs in 0.000 seconds
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS
ok github.com/spilth/ogay 0.015s
Running Suite: Ogay Suite
=========================
Random Seed: 1533304334
Will run 1 of 1 specs
• Failure [0.000 seconds]
Ogay
/Users/bkelly/go/src/github.com/spilth/ogay/ogay_test.go:9
Translating words
/Users/bkelly/go/src/github.com/spilth/ogay/ogay_test.go:10
Words starting with a vowel
/Users/bkelly/go/src/github.com/spilth/ogay/ogay_test.go:11
translated them correctly [It]
/Users/bkelly/go/src/github.com/spilth/ogay/ogay_test.go:12
Expected
<string>: appleway
to equal
<string>: appleways
/Users/bkelly/go/src/github.com/spilth/ogay/ogay_test.go:13
------------------------------
Summarizing 1 Failure:
[Fail] Ogay Translating words Words starting with a vowel [It] translated them correctly
/Users/bkelly/go/src/github.com/spilth/ogay/ogay_test.go:13
Ran 1 of 1 Specs in 0.001 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestOgay (0.00s)
FAIL
exit status 1
FAIL github.com/spilth/ogay 0.015s