Test
Contents
Test Driven Development: what it is, and what it is not.
basic concept
unit test; integration test
- unit: small piece of code
- integration test a gropu of unit
TTD
test driven development
- write test
- implement the code
- Refactor
test first development:
先写单元测试,再实现具体逻辑,再重构 以单元测试作为驱动;
test sql
- sql mock
|
|
- real test
testMain
|
|
test 执行开始或者之后做一些必要动作
-
之前
//连接数据库
-
之后
关闭数据库
Test In GO;
|
|
Mock in Go
interface: GetSth(a int) int
func (mockObj) GetSth() int{}
command
go test [source] [flags] benchmark:
-
flages
- -count: run each test benchmark n times;
- -run: run only matched test/example;
- -bench: run
-
test
- source
- local: filename
go test
,go test a.go
- package mode(will cache): . , ./.. packagename
- local: filename
- source
-
benchmark
1 2 3 4
BenchmarkFib10 483523 2458 ns/op 504 B/op 6 allocs/op # 2458: cost 2458ns # cost:504 # cost: 6 allocation
- -bench=regex;
- -benchmem: memory data;
test command
-
types
- TestXxxx
- BenchmarkXxxx
- ExampleXxxx: simple test;
-
Benchmark run methods N times in , the get the average second 1 operation: N ns; 1 operation