Testing: do more with less (JSNation 2024)

eugef 23 views 15 slides Jun 18, 2024
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

How can you be confident that your code is well-tested? For me, the criteria are straightforward: you feel comfortable deploying it automatically to production on a Friday evening, and the release pipeline stays as green as an evergreen tree. In this talk, I'll share some approaches that I am fo...


Slide Content

Testing:
Do More
With Less
Practical approach to test
Node.js web-apps, APIs, BFFs
Eugene Fidelin | JSNation 2024 Amsterdam

2
Is your code well-tested?
Do you feel comfortable
deploying it automatically
to production on a Friday
evening?
Does your release pipeline
stay as green as an
evergreen tree?

Why? DORA metrics
Lead Time for Changes
The amount of time it takes a
commit to get into production
Change Failure Rate
The percentage of deployments
causing a failure in production
3
Deployment Frequency
How often a team successfully
releases to production
Time to restore service
How long it takes a team to recover
from a failure in production

Static
Unit tests
Integration
tests
End to end
tests
Costs Confidence Speed
Very high High Low
Low - Medium Very good High
Low Average High
Very low Low Very high
4
How? Testing trophy

Steps to approach testing
0 2 41
Step 0
Enable static linters,
and type checks
Step 2
Write unit tests for
reusable parts and code
without coverage
Step 4
Use metrics, tracing,
logging to identify
anomalies on production
3
Step 3
Write very few e2e
tests only for the most
business critical flow(s)
Step 1
Create integration
tests for all happy and
non-happy flows

Node.js app architecture
6
App code
Code to test
External lib/service

Unit test
7
App code
Code to test
External lib/service
Test coverage

Scenario of integration test
8
Given anincoming request
app makesspecified API calls
and returns theexpected response

Focused Integration test
9
App code
Code to test
External lib/service
Test coverage
Mocks

Black-box Integration test
10
App code
Code to test
External lib/service
Test coverage
Mocks

Broad Integration test
11
App code
Code to test
External lib/service
Test coverage
Mocks

End to end test
12
App code
Code to test
External lib/service
Test coverage

Key takeaways
13
Adopt Testing Trophy
01
Start with Integration tests
02
Reduce amount of
e2e test
03
Measure impact with
DORA metrics

04

Tools
superagent
Simulate incoming HTTP
request
node-mocks-http
Mock Express.js
request/response objects
Jest / Vitest
Test framework, mock
deps, snapshots
nock
Mock downstream
HTTP API calls
14
Cypress.io /
Playwright
Testing in browser

CREDITS: This presentation template was
created by Slidesgo, including icons by Flaticon
and infographics & images by Freepik
Thanks!
15
Eugene Fidelin
Engineering Manager @
eugene.fi[email protected]
linkedin.com/in/eugef
medium.com/@EugeneFidelin