Esta sesión está constituida por dos partes: en la primera explicaré en qué consiste el test driven development y cómo funciona a grandes rasgos; posteriormente mostraré ejemplos de cómo se puede implementar en el lenguaje de programación Go utilizando el framework Ginkgo y la biblioteca de afirmaciones Gomega.
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Test Driven Development en Go con Ginkgo y Gomega
1. TDD in Go with Ginkgo and
Gomega
Presenta:
Eddy Reyes
2. Eddy Reyes
Founder of Mindsight
● AI for Software Project Management
● Tells you when tasks will be finished by watching code changes.
3. Test Driven Development
● Write the test
● Watch it fail
● Implement new code
● Test passes
I CAN HAZ
DESIGN??
4. Anatomy of a Test
● GIVEN: X is true
● WHEN: Y happens
● THEN: Z must be true
5. TDD What’s it Good For?
● Helps you create unit tests
● Tests are enforceable design spec
● Forces deep understanding of design before coding
6. TDD, Ain't Nobody Got Time For That
● TDD takes up front additional effort
● Tests are hard- code that reasons about the behavior of code
● Design must be understood before test is written
7. TDD Pro Tips
● Divide and Conquer! Work with the smallest piece possible
● Experiment, prototype, learn your design
● Throw away your prototype! Start fresh with tests first
8. Go testing Package
In a file named XX_test.go:
func TestMyThing(t *testing.T) {
result, err := DoMyThing()
if err == nil {
t.Error(“Failed with error:”, err)
}
if !result {
t.Error(“Expected true”)
}
}
9. Go Testing Capabilities (Batteries Included)
Run your tests:
$ go test -race
… Also tells you if a race condition is detected in your code
Compute test coverage:
$ go test -coverprofile=coverage.out
$ go tool cover -html=coverage.out
10. Alternative Testing Tools
Ginkgo / Gomega
● Jasmine clone for Go
● Ginkgo- BDD-style test specification
● Gomega- Assertion syntax
Convey
● https://github.com/smartystreets/goconvey