1. 单元测试

image.png
image.png

go test -v -cover go get -u github.com/stretchr/testify

2. Benchmark

go test -bench=.

  1. ok go-learning/src/ch29/benchmark 0.334s

go test -bench=”.”

  1. goos: windows
  2. goarch: amd64
  3. pkg: go-learning/src/ch29/benchmark
  4. cpu: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  5. BenchmarkConcatStringByAdd-8 9803656 120.7 ns/op
  6. BenchmarkConcatStringByBytesBuffer-8 18998974 59.38 ns/op
  7. PASS
  8. ok go-learning/src/ch29/benchmark 2.548s

go test -bench=”.” -benchmem

  1. goos: windows
  2. goarch: amd64
  3. pkg: go-learning/src/ch29/benchmark
  4. cpu: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  5. BenchmarkConcatStringByAdd-8 10114231 120.5 ns/op 16 B/op 4 allocs/op
  6. BenchmarkConcatStringByBytesBuffer-8 20040949 59.59 ns/op 64 B/op 1 allocs/op
  7. PASS
  8. ok go-learning/src/ch29/benchmark 2.642s

image.png
image.png

3. Behavior Driven Development

image.png
image.png
image.png
image.png
image.png