forked from RedHatOfficial/GoCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson5_ru.slide
More file actions
90 lines (70 loc) · 3.31 KB
/
lesson5_ru.slide
File metadata and controls
90 lines (70 loc) · 3.31 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
Урок 5. Тестирование, CGo и инструменты
Lesson 5
27 Jul 2025
Tags: golang, go
Перевод команды GoCourse
Jakub Čajka <jcajka@redhat.com>
Red Hat, Inc.
https://github.com/RedHatOfficial/GoCourse
@RedHat
* Источники
- [[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
* Тестирование и бенчмаркинг в Go
- Unit test "фреймворк" интегрирован в команду Go
- `go` `test`
- (Микро)Benchmark "фреймворк" также является его частью
- `go` `test` `-bench` `.`
- пакет `testing`
- код должен быть "vetable", проходить проверку `go` `vet`
* Тесты
- в файлах `_test.go`
- все функции `Test*(t` `*testing.T)` выполняются
* Test main
- `func` `TestMain(m` `*testing.M)`
- `m.Run`
- предоставляет возможность настройки, передачи CLI флагов,...
- выполнения тестов, которые не подходят под базовый фреймворк, и т.д.
- посмотрите misc/cgo GC тесты
* Бенчмарки
- в файлах `_test.go`
- все функции `Benchmark*(b` `*testing.B)` выполняются
- можно тестировать не только производительность(`-bench`), но и использование памяти(`-benchmem`)
* Assertions в Go
- `assert` не является ключевым словом в Go
- но существуют assert-подобные функции и методы
- сторонние библиотеки
* Assertions в Go (factorial)
.code testing/assertions/assertions1/factorial.go
* Assertions в Go (factorial)
.code testing/assertions/assertions1/factorial_test.go
* Больше assertions-подобных функций
.code testing/assertions/assertions2/factorial_test.go
* Использование "Dot import"
.code testing/assertions/assertions3/factorial_test.go
* CGO
- связь языков Go и C
- в обоих направлениях
- прост в использовании
- снижает производительность
- может понадобиться для интеграции с существующими библиотеками
- используйте осторожно
* CGO - пример
.code lesson5/cgo-inlinec/cgo-inlinec.go HLcgo
* CGO - пример
.code lesson5/cgo-strings/cgo-string.go /memory management/,/memory management end/
* CGO - Math test and benchmark
.code lesson5/cgo-math-test-bench/cgo-math_test.go /T1/,/T1/
.code lesson5/cgo-math-test-bench/cgo-math_test.go /T2/,/T2/
.code lesson5/cgo-math-test-bench/cgo-math_test.go /benchmark/,/benchmark/
#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