10 ways to shoot yourself in the foot with tests - Shai Geva, PyCon IL, 2024
ShaiGeva1
62 views
121 slides
Sep 16, 2024
Slide 1 of 121
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
About This Presentation
This document discusses 10 ways that tests can "shoot yourself in the foot" by being poorly designed or implemented. It covers issues like having no tests, unclear tests, tests that are not isolated, improper test scope, overuse of test doubles, and tests that are too slow. The key lessons...
This document discusses 10 ways that tests can "shoot yourself in the foot" by being poorly designed or implemented. It covers issues like having no tests, unclear tests, tests that are not isolated, improper test scope, overuse of test doubles, and tests that are too slow. The key lessons are that tests need to be fast, isolated, and focused on validating core behaviors to form an effective feedback loop for developers.
Size: 14.03 MB
Language: en
Added: Sep 16, 2024
Slides: 121 pages
Slide Content
TESTING
FOOTGUNS;
10 WAYS TO SHOOT YOURSELF IN THE FOOT
WITH TESTS
Shai Geva | Tech Lead @Sayata | @shai_ge
Shai Geva
~20 years making software
Love testing
Tech Lead, Sayata
COMPLETE STORY
COHESIVE WHOLE
BEHAVIOR / IMPLEMENTATION
Book Store MySQL
BEHAVIOR TEST IMPLEMENTATION TEST
BEHAVIOR TEST IMPLEMENTATION TEST
WITH BUG
WITHOUT BUG
BEHAVIOR TEST IMPLEMENTATION TEST
WITH BUG
WITHOUT BUG
def test_editing_description_sets_correct_value():
BEHAVIOR TEST IMPLEMENTATION TEST
BEHAVIOR TEST IMPLEMENTATION TEST
# Create book
# Edit book
# Get updated description
# Assert correctness
# Create book
# Edit book
# Get updated description
# Assert correctness
def test_editing_description_sets_correct_value():
# Create book - API
requests.post(...
# Edit book - API
requests.post(...
# Get updated description - API
new_desc = requests.get(…
# Assert correctness
assert new_desc == ...
# Create book - DB
# Edit book - API
# Get updated description - DB
# Assert correctness
BEHAVIOR TEST IMPLEMENTATION TEST
def test_editing_description_sets_correct_value():
# Create book - DB
DbBook.creat_new(...
# Edit book - API
requests.post(...
# Get updated description - DB
new_desc = DbBook.query_one(…
# Assert correctness
assert new_desc == ...
BEHAVIOR TEST IMPLEMENTATION TEST
# Create book - API
requests.post(...
# Edit book - API
requests.post(...
# Get updated description - API
new_desc = requests.get(…
# Assert correctness
assert new_desc == ...
def test_editing_description_sets_correct_value():
BEHAVIOR TEST IMPLEMENTATION TEST
# Create book - DB
DbBook.creat_new(...
# Edit book - API
requests.post(...
# Get updated description - DB
new_desc = DbBook.query_one(…
# Assert correctness
assert new_desc == ...
# Create book - API
requests.post(...
# Edit book - API
requests.post(...
# Get updated description - API
new_desc = requests.get(…
# Assert correctness
assert new_desc == ...
def test_editing_description_sets_correct_value():WHAT
COHESIVE HOW
INCOHESIVE
OUR CODE CHANGE
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
BOOK TABLE
DESCRIPTION ID …
BOOK TABLE
DESCRIPTION ID …
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
BEHAVIOR
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
BEHAVIOR
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
BEHAVIOR
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
IMPLEMENTATION
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
IMPLEMENTATION
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
IMPLEMENTATION
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
BEHAVIOR
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
IMPLEMENTATION
TEST
BOOK TABLE
DESCRIPTION DESC_ID ID
DESCRIPTION TABLE
VALUE ID
Book Store
/edit-book
/new-book
/get-book
IMPLEMENTATION
TEST
TOOLS:
>>> pytest-watch
Re-run tests on file changes
>>> pytest-testmon
Only run tests that can be impacted
by the code that changed
>>> pytest-xdist
Run tests in parallel
>>> pytest-env, pytest-dotenv
Deal with env vars
>>> unittest subTest Organizing test output
when you have large tests.
For pytest: pytest-subtests
>>> factory-boy, faker
Generate random test data
>>> hypothesis !
Property-based testing - for getting strong
tests.
>>> coverage.py
Python test-coverage
>>> vcrpy
Record HTTP requests
Slides:
bit.ly/testing_footguns_pycon_il_2024
1.There are no tests
2.Untested tests
3.No Locality of Behavior
4.Unclear language
5.Testing too many things
6.The tests are not isolated
7.Improper scope
8.Test doubles
9.Slow tests
10.Wrong priorities