Slide 1

Slide 1 text

Тестирование в Golang Алик Хилажев Marketplace Technologies

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Продукты • KazanExpress.ru • eco.KazanExeress.ru • ЛК для продавцов sellers.kazanexpress.ru • Приложения для iOS и Android

Slide 4

Slide 4 text

План • Основы (go test, TestXXX, BenchmarkXXX) • TableDrivenTests • assert либы: за и против • Mock • suit testing

Slide 5

Slide 5 text

pkg/testing • TestXXX(t *testing.T) • название файлов - xxx_test.go • запуск через go test …

Slide 6

Slide 6 text

go test

Slide 7

Slide 7 text

go test

Slide 8

Slide 8 text

benchmarks

Slide 9

Slide 9 text

TableDrivenTests

Slide 10

Slide 10 text

TableDrivenTests

Slide 11

Slide 11 text

asserts за и против • No doubt assertion libs can reduce typing and repetition. • Reductions in typing with assertion libs are not profound. • The necessary repetition without assertion libs can be minimised. • Some repetition locally can increase readability at no great cost. • Some assertion libs tend to reduce the value of tests as documentation. • You are adding another (often large) library dependency with associated maintenance overhead, bugs, life cycle etc. • It is a commitment that will stay with you for a long time, and it is expensive to undo. http://danmux.com/posts/the_cult_of_go_test/

Slide 12

Slide 12 text

asserts за и против • Type safety is often dropped - or needs explicit knowledge, or is only enforced at runtime. • There is a DSL to learn - often considerable - an extra burden on the team and new members forever. • The libs often introduce multiple ways to achieve the same thing, or worse: similar but subtly different ways. • It does not resolve the infighting - a new dev will argue for their favourite lib. • Adding the assertion lib in the middle of a project adds an annoying inconsistency. http://danmux.com/posts/the_cult_of_go_test/

Slide 13

Slide 13 text

mocks mockgen github.com/alikhil/go-testing/internal/repository Repository

Slide 14

Slide 14 text

mocks

Slide 15

Slide 15 text

mocks

Slide 16

Slide 16 text

suite testing https://github.com/stretchr/testify/suite - (*suite) SetupSuite() - (*sutie) BeforeTest() - (*suite) AfterTest() - (*suite) TearDownSuite() suite.Run()

Slide 17

Slide 17 text

suite testing

Slide 18

Slide 18 text

suite testing

Slide 19

Slide 19 text

Бонус! GOMEETUP19 - промокод на 300р