https://github.com/gunjan5/go-test-driven-development
:hammer: :wrench: Test Driven Development :repeat: with Golang :hamster:
https://github.com/gunjan5/go-test-driven-development
benchmark go golang tdd test testing
Last synced: 6 months ago
JSON representation
:hammer: :wrench: Test Driven Development :repeat: with Golang :hamster:
- Host: GitHub
- URL: https://github.com/gunjan5/go-test-driven-development
- Owner: gunjan5
- License: mit
- Created: 2016-03-18T19:14:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-20T20:28:53.000Z (almost 8 years ago)
- Last Synced: 2023-03-01T19:46:22.701Z (over 2 years ago)
- Topics: benchmark, go, golang, tdd, test, testing
- Language: Go
- Homepage:
- Size: 147 KB
- Stars: 31
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :wrench::nut_and_bolt::hammer::repeat:Test Driven Development (TDD) with Go :raised_hands:
I will be following TDD approach, where I write the test first, and then write the main code to make it pass eventually### Naming conventions:
- Test file : xxx_test.go
- Test func : TestXxx
- Benchmark : BenchmarkXxx
- Example : ExampleXxx
- Custom Test runner: TestMain### Tips:
- Follow the AAA rule for EACH test
- [x] Arrange
- [x] Act
- [x] Assert (assert only one set of actions)
- DRY (Don't Repeat Yourself) also applies to Tests## Notes:
- `t.Error()` = `t.Log()`+`t.Fail()` //t.Fail() fails the current test but continues with rest of the tests
- `t.Fatal()` = `t.Log()`+`t.FailNow()` // t.Fatal() and t.FailNow() fails & stops ALL the tests### Commands:
- `go test` //for normal testing in the current dir
- `go test -v` //for verbose output
- `go test ` // to test the package
- `go test -run ` //to run tests only on a specific function instead of the whole file
- `go test -timeout ` //times out & panics the test if not finished in the specified timeout i.e. 2s, 1m, etc.
- `go test -v -short`//Skip some long running tests (Goes with `if testing.Short(){t.Skip("Skipping")}` in the Test func)### Coverage:
- `go test -cover` //to see test coverage
- `go test -coverprofile=coverage.out; go tool cover -html=coverage.out` //this will open a html in browser with showing which lines of code are covered in green (and not covered with red) (sample image below)
### Benchmark:
- `go test -bench .` //run benchmark in the current dir
- `go test -v -bench .` //verbose