forked from RedHatOfficial/GoCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_ru.slide
More file actions
163 lines (98 loc) · 4.83 KB
/
testing_ru.slide
File metadata and controls
163 lines (98 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
Тестирование в языке Go
Фреймворки тестирования Golang
02 Nov 2019
Tags: golang, go, testing
Pavel Tišnovský
Red Hat, Inc.
ptisnovs@redhat.com
https://github.com/RedHatOfficial/GoCourse
@RedHat
* Sources
- [[https://github.com/RedHatOfficial/GoCourse]]
.image ./common/qr_address.png
* Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/fiveyears.jpg
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/fiveyears.jpg _ 900
* Фреймворки тестирования Golang
- Модульное тестирование
- BDD тестирование
- Expect-подобные фреймворки и библиотеки
- Тестирование REST API
- Анализ производительности
* Пирамида тестов и конус мороженого
[[https://watirmelon.files.wordpress.com/2018/02/automated-testing-pyramid-with-eye.jpg?w=840]]
[[https://watirmelon.files.wordpress.com/2018/02/software-testing-icecream-cone-antipattern.jpg?w=840]]
* Модульное тестирование
- Стандартный пакет `testing`
- Вспомогательный инструмент `go-carpet`
- Расширения (`testify`)
- Альтернативный пакет `oglematchers`
- Комбинация `ogletest` и `oglematchers`
- Пакет `assertions`
- Пакет `goblin`
* Стандартный пакет "testing"
- Основан на пакете [[https://pkg.go.dev/testing]]
- Исходные файлы, содержащие тесты, должны заканчиваться на `_test.go`
- Каждый тест должен быть сохранен в функции с именем `func` `TestXxx(*testing.T)`
- Базовые методы для структуры `testing.T` (тип данных)
* Стандартный пакет "testing"
- В пакете `testing` нет "утверждений"!
- `Log(args` `...interface{})`
- `Skip(args` `...interface{})`
- `Error(args` `...interface{})`
- `Fatal(args` `...interface{})`
- `Fail()`
- `FailNow()`
* Стандартный пакет "testing"
- Форматирование вывода
- `Logf(format` `string,` `args` `...interface{})`
- `Skipf(format` `string,` `args` `...interface{})`
- `Errorf(format` `string,` `args` `...interface{})`
- `Fatalf(format` `string,` `args` `...interface{})`
* Файлы модульных тестов
- Обычно хранятся в `package_test.go`
- Могут быть разделены на столько файлов, сколько необходимо
- Так называемые табличные тесты
- Обычно используется массив/срез структур с входными данными и ожидаемым выводом
* Как запустить модульные тесты
- Базовая команда: `go` `test`
- Обычно: `go` `test` `./...`
- Можно указать регулярное выражение для выбора только подмножества тестов
* Простейший пример
.code testing/testing/tests01/add.go
* Простейший тест
.code testing/testing/tests01/add_test.go
* Запуск тестов и результат
.code testing/testing/tests01/run.txt
* Табличный тест
.code testing/testing/tests02/add_test.go
* Запуск табличного теста
.code testing/testing/tests02/run.txt
* Простейший пример с некорректными данными
.code testing/testing/tests03/add_test.go
* Запуск теста с некорректными данными
.code testing/testing/tests03/run.txt
* Подтесты
.code testing/testing/tests04/add_test.go
* Запуск подтестов
.code testing/testing/tests04/run.txt
* Пропуск тестов
.code testing/testing/tests05/add_test.go
* Запуск с пропуском
.code testing/testing/tests05/run.txt
* Покрытие кода тестами
go test -cover
* Покрытие кода тестами с деталями
go test -cover -coverprofile=coverage.out
go tool cover -html=coverage.out
* Тестирование производительности
- Бенчмарки являются частью стандартных инструментов Go
- Могут комбинироваться с функциями и методами профилирования
#last slide
* Больше Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/bumper.png
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/bumper.png _ 900