SlideShare a Scribd company logo
1 of 24
Download to read offline
Multiply your Testing
Effectiveness with
Parameterized Testing
Brian Okken
The Immense Value of
Automated Tests
and
How to Avoid Writing Them
Alternate title
Brian Okken
Brian Okken
weekly Python podcasts A book
I work here
new meetup there, Python PDX West Oct 8, 6 pm
Python-PDX-West
Outline
• A development workflow
• which includes a build pipeline
• which includes tests
• that I don’t want to spend too much time writing
• so most of my test cases use parametrization*
*one of many techniques I use to avoid writing tests
Target Workflow
Time
main
dev / fix / feature
branches
Merge Request /
Pipeline Runs
Drawing elements: Vincent Driessen
License: Creative Commons
Merge Request /
Pipeline Runs
• Branch off main
• Solo or collaborating
• Tests and code merge together
• Pipeline does magic
Developer Workflow
• Write some code & some tests.
• Commit code regularly
• Merge Request / Pull Request
• Pipeline does most of the work, build, test, etc.
• Reviewers get notified.
• Reviewers think my code is awesome & accept it.
• Merge finishes
• Fist bumps, high fives, etc.
• Repeat
After merge, I know
• I didn't break anything that used to work.
• New features are tested with new tests.
• Future changes won’t break current features.
• Team understands code and tests.
• The code is ready for users.
• I can refactor my code if I'm not proud of it and
know the tests will make sure everything is ok.
Reviewer knows,
before the review
✓ Static analysis
✓ Style guide checks
✓ Code coverage has not dropped.
✓ Tests all pass
✓ Legacy functionality working.
✓ New tests pass.
Reviewer Focus
• Just the code + test for this feature.
• Do I understand the code and the tests?
• Enough to maintain it if the original dev is on vacation?
• Are the tests sufficient for the new functionality?
Team Lead / Manager View
• Awesome code keeps popping out
• The tests have our backs.
• We’re moving fast.
• Big refactoring/rewrites are low risk.
• I can understand the tests.
• Maybe even write some tests myself.
Tests in a Pipeline
• fail fast
• negative feedback as fast as possible
• feeds into a deploy stage, maybe
smoke
tests
longer
running
tests
quick but
thorough
new tests
static
analysis
13
Tests to support this
• Customer focused
• Developer focused
• Feature / functionality focused
• Risk focused
• Complete but not crazy complete
• Have to be readable, fast to write, easy to maintain
Parametrization
• Many test cases with one test function.
• pytest has a few strategies for this.
• function parametrization
• fixture parametrization
• a hook function: pytest_generate_tests()
17
cards
$ cards
ID owner done summary
---- ------- ------ ————
$ cards add prepare for talk
$ cards add give talk
$ cards
ID owner done summary
---- ------- ------ ----------------
1 prepare for talk
2 give talk
$ cards update -o okken 1
$ cards update -o okken 2
$ cards finish 1
$ cards
ID owner done summary
---- ------- ------ ----------------
1 okken x prepare for talk
2 okken give talk
a test
import cards
from cards import Card
def test_add(tmp_path):
cards.set_db_path(tmp_path)
cards.connect()
a_card = Card('first task', 'brian', False)
id = cards.add_card(a_card)
c2 = cards.get_card(id)
cards.disconnect()
assert a_card == c2
push setup/teardown
into fixtures
@pytest.fixture(scope='session')
def db(tmp_path_factory):
d = tmp_path_factory.mktemp('cards_db')
cards.set_db_path(d)
cards.connect()
yield
cards.disconnect()
@pytest.fixture(scope='function')
def empty_db(db):
cards.delete_all()
def test_add(empty_db):
a_card = Card('first task', 'brian')
id = cards.add_card(a_card)
c2 = cards.get_card(id)
assert a_card == c2
so we can focus on this test
def test_add(empty_db):
a_card = Card('first task', 'brian', False)
id = cards.add_card(a_card)
c2 = cards.get_card(id)
assert a_card == c2
so we can focus on this test
def test_add(empty_db):
a_card = Card('first task', 'brian', False)
id = cards.add_card(a_card)
c2 = cards.get_card(id)
assert a_card == c2
@dataclass
class Card:
summary: str = None
owner: str = None
done: bool = None
id: int = field(default=None, compare=False)
But what about all
the other kinds of cards?
Parametrization !!!
@pytest.mark.parametrize('a_card', [
Card('first task', 'brian', False),
Card(),
Card(summary='do something'),
Card(owner='brian'),
Card(done=True)],ids=repr)
def test_add(empty_db, a_card):
id = cards.add_card(a_card)
c2 = cards.get_card(id)
assert a_card == c2
function parametrization
@pytest.fixture(params=[
Card('first task', 'brian', False),
Card(),
Card(summary='do something'),
Card(owner='brian'),
Card(done=True)], ids=repr)
def a_card(request):
return request.param
def test_add(empty_db, a_card):
id = cards.add_card(a_card)
c2 = cards.get_card(id)
assert a_card == c2
fixture parametrization
def pytest_generate_tests(metafunc):
if "a_card" in metafunc.fixturenames:
metafunc.parametrize("a_card", [
Card('first task', 'brian', False),
Card(),
Card(summary='do something'),
Card(owner='brian'),
Card(done=True)], ids = repr)
def test_add(empty_db, a_card):
id = cards.add_card(a_card)
c2 = cards.get_card(id)
assert a_card == c2
pytest_generate_tests
Thank You
• twitter: @brianokken
• book: Python Testing with pytest
• pragprog.com/book/bopytest/python-testing-with-pytest
• also: pytestbook.com
• podcasts
• testandcode.com
• pythonbytes.fm
• https://www.me
• meetup
• meetup.com/Python-PDX-West/
• First one: Tuesday, Oct 8, Hillsboro

More Related Content

What's hot

YOW2020 Linux Systems Performance
YOW2020 Linux Systems PerformanceYOW2020 Linux Systems Performance
YOW2020 Linux Systems PerformanceBrendan Gregg
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005dflexer
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerunidsecconf
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityBrendan Gregg
 
LPC2019 BPF Tracing Tools
LPC2019 BPF Tracing ToolsLPC2019 BPF Tracing Tools
LPC2019 BPF Tracing ToolsBrendan Gregg
 
Performance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedPerformance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedBrendan Gregg
 
Kernel development
Kernel developmentKernel development
Kernel developmentNuno Martins
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceSUSE Labs Taipei
 
bcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesbcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesIO Visor Project
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversSatpal Parmar
 
Linux Performance Tools 2014
Linux Performance Tools 2014Linux Performance Tools 2014
Linux Performance Tools 2014Brendan Gregg
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitAndrea Righi
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPFAlex Maestretti
 
Trace kernel code tips
Trace kernel code tipsTrace kernel code tips
Trace kernel code tipsViller Hsiao
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 
re:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at Netflixre:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at NetflixBrendan Gregg
 
Linux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFLinux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFBrendan Gregg
 
Low Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFLow Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFAkshay Kapoor
 

What's hot (20)

YOW2020 Linux Systems Performance
YOW2020 Linux Systems PerformanceYOW2020 Linux Systems Performance
YOW2020 Linux Systems Performance
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerun
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
 
LPC2019 BPF Tracing Tools
LPC2019 BPF Tracing ToolsLPC2019 BPF Tracing Tools
LPC2019 BPF Tracing Tools
 
Performance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedPerformance Wins with BPF: Getting Started
Performance Wins with BPF: Getting Started
 
Kernel development
Kernel developmentKernel development
Kernel development
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
bcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesbcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challenges
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Linux Performance Tools 2014
Linux Performance Tools 2014Linux Performance Tools 2014
Linux Performance Tools 2014
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profit
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPF
 
Trace kernel code tips
Trace kernel code tipsTrace kernel code tips
Trace kernel code tips
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 
re:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at Netflixre:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at Netflix
 
Linux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFLinux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPF
 
Low Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFLow Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPF
 

Similar to Multiply your Testing Effectiveness with Parameterized Testing, v1

Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Scott Keck-Warren
 
C++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonC++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonClare Macrae
 
Workshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinWorkshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinMichelangelo van Dam
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)Peter Kofler
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIwajrcs
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World DominationcPanel
 
Machine learning in PHP
Machine learning in PHPMachine learning in PHP
Machine learning in PHPDamien Seguy
 
Machine learning in php singapore
Machine learning in php   singaporeMachine learning in php   singapore
Machine learning in php singaporeDamien Seguy
 
What is this agile thing anyway
What is this agile thing anywayWhat is this agile thing anyway
What is this agile thing anywayLisa Van Gelder
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Mark Niebergall
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1Blue Elephant Consulting
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Malinda Kapuruge
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonIneke Scheffers
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Ortus Solutions, Corp
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)Thierry Gayet
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Uma Ghotikar
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesTao Xie
 

Similar to Multiply your Testing Effectiveness with Parameterized Testing, v1 (20)

Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
C++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonC++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ London
 
Workshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinWorkshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublin
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Machine learning in PHP
Machine learning in PHPMachine learning in PHP
Machine learning in PHP
 
Machine learning in php singapore
Machine learning in php   singaporeMachine learning in php   singapore
Machine learning in php singapore
 
What is this agile thing anyway
What is this agile thing anywayWhat is this agile thing anyway
What is this agile thing anyway
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
Tdd
TddTdd
Tdd
 
Developers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomonDevelopers Testing - Girl Code at bloomon
Developers Testing - Girl Code at bloomon
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and Challenges
 

Recently uploaded

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 

Recently uploaded (20)

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

Multiply your Testing Effectiveness with Parameterized Testing, v1

  • 1. Multiply your Testing Effectiveness with Parameterized Testing Brian Okken
  • 2. The Immense Value of Automated Tests and How to Avoid Writing Them Alternate title Brian Okken
  • 3. Brian Okken weekly Python podcasts A book I work here new meetup there, Python PDX West Oct 8, 6 pm Python-PDX-West
  • 4. Outline • A development workflow • which includes a build pipeline • which includes tests • that I don’t want to spend too much time writing • so most of my test cases use parametrization* *one of many techniques I use to avoid writing tests
  • 5. Target Workflow Time main dev / fix / feature branches Merge Request / Pipeline Runs Drawing elements: Vincent Driessen License: Creative Commons Merge Request / Pipeline Runs • Branch off main • Solo or collaborating • Tests and code merge together • Pipeline does magic
  • 6. Developer Workflow • Write some code & some tests. • Commit code regularly • Merge Request / Pull Request • Pipeline does most of the work, build, test, etc. • Reviewers get notified. • Reviewers think my code is awesome & accept it. • Merge finishes • Fist bumps, high fives, etc. • Repeat
  • 7. After merge, I know • I didn't break anything that used to work. • New features are tested with new tests. • Future changes won’t break current features. • Team understands code and tests. • The code is ready for users. • I can refactor my code if I'm not proud of it and know the tests will make sure everything is ok.
  • 8. Reviewer knows, before the review ✓ Static analysis ✓ Style guide checks ✓ Code coverage has not dropped. ✓ Tests all pass ✓ Legacy functionality working. ✓ New tests pass.
  • 9. Reviewer Focus • Just the code + test for this feature. • Do I understand the code and the tests? • Enough to maintain it if the original dev is on vacation? • Are the tests sufficient for the new functionality?
  • 10. Team Lead / Manager View • Awesome code keeps popping out • The tests have our backs. • We’re moving fast. • Big refactoring/rewrites are low risk. • I can understand the tests. • Maybe even write some tests myself.
  • 11. Tests in a Pipeline • fail fast • negative feedback as fast as possible • feeds into a deploy stage, maybe smoke tests longer running tests quick but thorough new tests static analysis 13
  • 12. Tests to support this • Customer focused • Developer focused • Feature / functionality focused • Risk focused • Complete but not crazy complete • Have to be readable, fast to write, easy to maintain
  • 13. Parametrization • Many test cases with one test function. • pytest has a few strategies for this. • function parametrization • fixture parametrization • a hook function: pytest_generate_tests() 17
  • 14. cards $ cards ID owner done summary ---- ------- ------ ———— $ cards add prepare for talk $ cards add give talk $ cards ID owner done summary ---- ------- ------ ---------------- 1 prepare for talk 2 give talk $ cards update -o okken 1 $ cards update -o okken 2 $ cards finish 1 $ cards ID owner done summary ---- ------- ------ ---------------- 1 okken x prepare for talk 2 okken give talk
  • 15. a test import cards from cards import Card def test_add(tmp_path): cards.set_db_path(tmp_path) cards.connect() a_card = Card('first task', 'brian', False) id = cards.add_card(a_card) c2 = cards.get_card(id) cards.disconnect() assert a_card == c2
  • 16. push setup/teardown into fixtures @pytest.fixture(scope='session') def db(tmp_path_factory): d = tmp_path_factory.mktemp('cards_db') cards.set_db_path(d) cards.connect() yield cards.disconnect() @pytest.fixture(scope='function') def empty_db(db): cards.delete_all() def test_add(empty_db): a_card = Card('first task', 'brian') id = cards.add_card(a_card) c2 = cards.get_card(id) assert a_card == c2
  • 17. so we can focus on this test def test_add(empty_db): a_card = Card('first task', 'brian', False) id = cards.add_card(a_card) c2 = cards.get_card(id) assert a_card == c2
  • 18. so we can focus on this test def test_add(empty_db): a_card = Card('first task', 'brian', False) id = cards.add_card(a_card) c2 = cards.get_card(id) assert a_card == c2 @dataclass class Card: summary: str = None owner: str = None done: bool = None id: int = field(default=None, compare=False) But what about all the other kinds of cards?
  • 20. @pytest.mark.parametrize('a_card', [ Card('first task', 'brian', False), Card(), Card(summary='do something'), Card(owner='brian'), Card(done=True)],ids=repr) def test_add(empty_db, a_card): id = cards.add_card(a_card) c2 = cards.get_card(id) assert a_card == c2 function parametrization
  • 21. @pytest.fixture(params=[ Card('first task', 'brian', False), Card(), Card(summary='do something'), Card(owner='brian'), Card(done=True)], ids=repr) def a_card(request): return request.param def test_add(empty_db, a_card): id = cards.add_card(a_card) c2 = cards.get_card(id) assert a_card == c2 fixture parametrization
  • 22. def pytest_generate_tests(metafunc): if "a_card" in metafunc.fixturenames: metafunc.parametrize("a_card", [ Card('first task', 'brian', False), Card(), Card(summary='do something'), Card(owner='brian'), Card(done=True)], ids = repr) def test_add(empty_db, a_card): id = cards.add_card(a_card) c2 = cards.get_card(id) assert a_card == c2 pytest_generate_tests
  • 23.
  • 24. Thank You • twitter: @brianokken • book: Python Testing with pytest • pragprog.com/book/bopytest/python-testing-with-pytest • also: pytestbook.com • podcasts • testandcode.com • pythonbytes.fm • https://www.me • meetup • meetup.com/Python-PDX-West/ • First one: Tuesday, Oct 8, Hillsboro