Skip to content

Commit 41e1062

Browse files
committed
First commit to ginkgo's slides
0 parents  commit 41e1062

File tree

11 files changed

+239
-0
lines changed

11 files changed

+239
-0
lines changed

ginkgo/book.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var _ = Describe("Book", func() {
2+
var (
3+
longBook Book
4+
shortBook Book
5+
)
6+
7+
BeforeEach(func() {
8+
longBook = Book{
9+
Title: "Les Miserables",
10+
Author: "Victor Hugo",
11+
Pages: 1488,
12+
}
13+
14+
shortBook = Book{
15+
Title: "Fox In Socks",
16+
Author: "Dr. Seuss",
17+
Pages: 24,
18+
}
19+
})
20+
21+
Describe("Categorizing book length", func() {
22+
Context("With more than 300 pages", func() {
23+
It("should be a novel", func() {
24+
Expect(longBook.CategoryByLength()).To(Equal("NOVEL"))
25+
})
26+
})
27+
28+
Context("With fewer than 300 pages", func() {
29+
It("should be a short story", func() {
30+
Expect(shortBook.CategoryByLength()).To(Equal("SHORT STORY"))
31+
})
32+
})
33+
})
34+
})

img/facet.png

34.5 KB
Loading

img/orthogonal.png

140 KB
Loading

img/profile.png

108 KB
Loading

img/tdd_steps.jpg

23.7 KB
Loading

img/test.png

11.7 KB
Loading

index.slide

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
Pruebas unitarias con Ginkgo
2+
5 de Mayo 2015
3+
Tags: go golang
4+
5+
Iván Jaimes
6+
Go Developer
7+
ivan@iver.mx
8+
http://iver.mx/
9+
@iver14
10+
https://github.com/ivan-iver
11+
12+
* Quién está presentando?
13+
14+
- Entuciasta de código
15+
- C#, ASP, JavaScript, Ruby, PHP, Go
16+
- Backend Developer at Nubleer
17+
.link http://www.nubleer.com/ Nubleer
18+
19+
* Pruebas Unitarias
20+
21+
- ¿Que es una prueba unitaria?
22+
- De la audiencia,
23+
¿Que lenguaje de programación usan?
24+
¿Quién usa pruebas unitarias?
25+
26+
* Historia
27+
28+
- TDD - Test Driven Development
29+
30+
Kent Beck 2002
31+
- (the first xUnit framework in Smalltalk I)
32+
- Test-first development
33+
34+
- BDD - Behaviour Driven Development
35+
36+
Dan North 2006
37+
- http://dannorth.net/
38+
39+
* Pruebas con "go test"
40+
41+
Ejecución de pruebas
42+
43+
$ go test
44+
45+
Detalle de la ejecución
46+
47+
$ go test -v
48+
49+
Ejecución de pruebas independientes
50+
51+
$ go test -run=ExpReg
52+
53+
Benchmark
54+
55+
$ go test -bench
56+
57+
func BenchmarkBigLen(b *testing.B) {
58+
big := NewBig()
59+
b.ResetTimer()
60+
for i := 0; i < b.N; i++ {
61+
big.Len()
62+
}
63+
}
64+
65+
* Ortogonalidad
66+
67+
Que un conjunto pequeño de elementos primitivos, se pueden
68+
combinar en un número relativamente pequeño de maneras para construir el software.
69+
70+
71+
72+
* Pruebas con "ginkgo"
73+
74+
Instalación
75+
76+
$ go get github.com/onsi/gomega
77+
$ go get github.com/onsi/ginkgo/ginkgo
78+
79+
Crear suite de pruebas
80+
81+
$ ginkgo bootstrap
82+
83+
Generar prueba unitaria
84+
85+
$ ginkgo generate
86+
87+
* Instrucciones básicas de ginkgo
88+
89+
- It
90+
- Describe && Context
91+
- BeforeEach && AfterEach
92+
- JustBeforeEach
93+
- By
94+
95+
* Algunas instrucciones de gomega
96+
97+
- Expect
98+
- To
99+
- Equal
100+
- Should
101+
- ShouldNot
102+
103+
* Especificaciones Pendientes (Pending Specs)
104+
105+
Permite marcar instrucciones o bloques como pendientes
106+
empleando la letra **P* o **X*
107+
108+
PDescribe("some behavior", func() { ... })
109+
PContext("some scenario", func() { ... })
110+
PIt("some assertion")
111+
PMeasure("some measurement")
112+
113+
XDescribe("some behavior", func() { ... })
114+
XContext("some scenario", func() { ... })
115+
XIt("some assertion")
116+
XMeasure("some measurement")
117+
118+
* Enfoque de especificaciones (Focused Specs)
119+
120+
Ejecución de un subconjunto de especificaciones
121+
122+
1) Anteponiendo la letra **F*
123+
124+
FDescribe("some behavior", func() { ... })
125+
FContext("some scenario", func() { ... })
126+
FIt("some assertion", func() { ... })
127+
128+
2) Empleando las banderas **--focus=REGEXP* y/o **--skip=REGEXP*
129+
130+
ginkgo -v --focus="Recibo"
131+
ginkgo -v --focus="InApp" --skip="Connect"
132+
ginkgo -v --skip="InApp"
133+
134+
* Otro Framework Interesante
135+
136+
- http://agouti.org/
137+
138+
139+
* Tips para escribir buenas pruebas unitarias
140+
141+
- Hacer cada prueba ortogonal
142+
- Evitar enunciados (asserts) innecesarios.
143+
- Probar una unidad de código a la vez.
144+
- Hacer “mocks” de los servicios y estados externos.
145+
- Evitar pre-condiciones innecesarias.
146+
- Evitar realizar pruebas de archivos de configuración
147+
- Asignar nombres de manera clara y consistente
148+
149+

now.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "time"
4+
5+
func main() {
6+
println(time.Now().Format("Mon 2006-02-01"))
7+
}

sing.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8">
4+
<title>Test</title>
5+
6+
<style type='text/css'>
7+
.sample{
8+
padding-left: 100px !important;
9+
margin: 50px 20px !important;
10+
border: solid 1px red;
11+
}
12+
</style>
13+
</head>
14+
<body id="body">
15+
<div class="sample">
16+
Estoy está dentro del código
17+
</div>
18+
</body>
19+
</html>

test/fib.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package fib
2+
3+
func FibFunc() func() uint64 {
4+
var a, b uint64 = 1, 1 // yes, it's wrong
5+
return func() uint64 {
6+
a, b = b, a+b
7+
return a
8+
}
9+
}

0 commit comments

Comments
 (0)