Dienstag, 17. November 2009

further go

Go doesn't have references.

all private functions begin with small character.
all public functions begin with big character.

To generate some Unit test:
name: mylib_test.go ( xxx_test.go )
the function must be called: TestXXX(t *testing.T) { ...
and import: "testing"

send Fatal error

if err != nil {
t.Fatalf("Myerror %q: %s", path, err)
}
// or
t.Errorf("bla bla %q ", path)


The T struct is:

type T struct {
errors string;
failed bool;
ch chan *T;
}


There are some functions XXXf are with format string

Fail(), Failed(): set the failed variable or ask them. (don't exit)
FailNow() set the fail and exit.

Log()/Logf(): set the errors string.
Error()/Errorf(): Log with Fail
Fatal()/Fatalf(): Log with FailNow


To test a package, write a set of Go source files
within the same package; give the files names of the
form *_test.go.

testing tool: gotest

func TestXxxx(t *testing.T)

create the file. later call gotest my_test.go

Keine Kommentare:

Kommentar veröffentlichen