Go and TDD

Create some code

1
2
3
4
5
6
7
// Package sandbox provides a library playground for code tests
package sandbox

// just sends back a word
func DoSomething(a string) string {
	return "Stupid"
}

Create some test

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
package sandbox_test

import (
	"sandbox"
	"strings"
	"testing"
)

func Test(t *testing.T) {
	t.Parallel()
	var want string = "Good"
	got := sandbox.DoSomething("Good")
	if strings.Compare(want, got) != 0 {
		t.Errorf("want %s, got %s", want, got)
	}
}

Get results

1
2
3
4
5
6
7
PS C:\WorkSpace\repos\go\SandBox> go test
--- FAIL: Test (0.00s)
    sandbox_test.go:14: want Good, got Stupid
FAIL
exit status 1
FAIL    sandbox 0.344s
PS C:\WorkSpace\repos\go\SandBox>