SlideShare a Scribd company logo
1 of 40
Download to read offline
Treat your unit tests as production code
Sandor DARGO (Amadeus)
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 1
Merci aux Sponsors !
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 2
Agenda
Define unit tests
You and unit tests
Test vs Production code
Problems with unit tests
Some solutions (no silver bullet)
Conclusion
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 3
Who am I?
Sándor DARGÓ
Software developer in Amadeus
Enthusiastic blogger http://sandordargo.com
Passionate traveller
Curious home baker and cook (@sourdad.baker)
Happy father of two
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 4
What is a unit test?
- Automated and repeatable
- Written in the language of the code
- Exercises a small part of the program (a unit)
Ideally, they are
- Independent
- Isolated
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 5
What is a (good) unit test?
“A unit test is a piece of code that invokes a unit of work and checks one
specific end result of that unit of work. If the assumptions on the end result
turn out to be wrong, the unit test has failed. A unit test’s scope can span as
little as a method or as much as multiple classes.” - The Art of Unit Testing
by Roy Osherove
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 6
Are you confident in your unit test
suite?
Are they all green?
Are they all executed?
Do they all assert something?
Do they all assert something meaningful?
Do they all assert a single logical thing?
Are they maintained?
Do you delete unit tests?
How frequently do you have to update them?
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 7
Differences between test and
production code
Differences between test and
production code
Form groups
You have 10 minutes to collect them
The pessimist realistic
“Production code is written in a hurry and is most often tested by users
because there wasn't time for QA and you were under pressure to
release.
Who gets time to write test code?”
Different “raison d’etre”
“Production code is is written to be robust (ideally, but not always the
case).”
“Test code is written just as a poc (proof of concept).”
“The difference is in purposes. Production code is for fulfilling the
contract. Test code is for verify this contract.”
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 11
Some more technical differences
“Production code is DRY vs test code is WET.”
“Production code is generic vs test code is specific”
“Production code has to be fast enough, test code must be super fast.”
A tool for write production code
and documentation
“Production code is only what is necessary to get the test code to pass.
And then refactored to make it clean.”
“Test code is easily readable and rather blunt. When someone wants to
know how the system works, you should be able to point them to the
tests that prove the functionality.”
What is common in the previous
answers?
Tests are specific
They document something
Production behaviour
Contract
No mention of poor architecture, poor coding practices. Except for the
WET part.
Why are those differences?
The rest makes sense:
Differences in purposes
Not in implementation details
Do we have a good reason to have worse quality?
Problems with unit tests
Collect your challenges
Form groups
You have 10 minutes to collect them
Common problems with test code
Show its value
Dependency injection
What to test? (public vs private; GUI)
Target code coverage? Does it matter?
TDD or not, test first or not?
Unit test vs integration test?
Test legacy code
Mocking
Common problems with test code
Missing assertions
Multiple assertions
Tests invoking other tests
Logic inside test code
Lack of coverage
Slowness (DB, I/O access)
Dependency between tests
Coupling, fragile test code
Common problems with test code
We have to write them
External dependencies
Fragile test code
Tests? Like production! You have
to write them!
Is it optional?
Client doesn’t want to pay for it?
Manager doesn’t want it?
Don’t know how to write it?
External dependencies
External dependencies
Cannot instantiate code under test
Non-deterministic results
Slow execution time
Cut the external dependencies
DB and IO operations make tests
Dependent
Non-deterministic
Error-prone
Slow
The banana, monkey, jungle
problem
“The problem with object-oriented languages is they’ve got all this
implicit environment that they carry around with them. You wanted a
banana but what you got was a gorilla holding the banana and the
entire jungle.”
Code example
Welcome to the jungle!
class Alarm {
public:
Alarm();
void check();
bool isAlarmOn();
protected:
Sensor m_sensor;
double m_lowPressureTreshold, m_highPressureTreshold;
bool m_alarmOn;
};
double Sensor::popNextPressurePsiValue() { return random();}
Bring your own device
class Alarm {
public:
Alarm(Sensor* sensor, double lowP, double highP);
void check();
bool isAlarmOn();
protected:
Sensor* m_sensor;
double m_lowPressureTreshold, m_highPressureTreshold;
bool m_alarmOn;
};
Fragile test code
Do you have the Fragile Test
Problem?
Test code is highly coupled to production code
If code changes, tests are broken
Cannot refactor
We must keep refactoring
Refactoring is part of TDD
Adding tests after the fact will also require refactoring
What happens when you refactor?
class SUT:
def operation_a(): pass
def operation_b(): pass
class TestSUT(unittest.TestCase):
def test_operation_a(): pass
def test_operation_b(): pass
What happens when you refactor?
class SUT:
def operation_a(): pass
def sub_operation_a(): pass
def operation_b(): pass
def sub_operation_b(): pass
class TestSUT(unittest.TestCase):
def test_operation_a(): pass
def test_operation_b(): pass
def test_sub_operation_a():
pass
def test_sub_operation_b():
pass
What happens when you refactor?
class SUT:
def operation_a(): pass
def operation_b(): pass
def sub_operation_a(): pass
def sub_operation_b(): pas
def common_sub_operation():
pass
class TestSUT(unittest.TestCase):
def test_operation_a(): pass
def test_operation_b(): pass
def test_sub_operation_a(): pass
def test_sub_operation_b(): pass
def test_common_sub_operation():
pass
What happens when you refactor?
class SUT(CommonSUT):
def operation_a(): pass
def operation_b(): pass
def common_sub_operation():
pass
class CommonSUT:
def sub_operation(): pass
class TestSUT(unittest.TestCase):
def test_operation_a(): pass
def test_operation_b(): pass
def test_common_sub_operation():
pass
class TestCommonSUT(unittest.TestCase):
def test_sub_operation(): pass
Test contravariance
“The structure of your tests should not be a mirror of the structure of
your code. The fact that you have a class named X should not
automatically imply that you have a test class named XTest.” - Uncle
Bob
What else can you do?
Test behavior
Don’t mimic production code structure
Let test code evolve on its own
Don’t be a micromanager
Should we test private?
No, only the API
Should we test every single aspect?
Don’t test every bits of implementation
Conclusion
Unit testing is difficult, but learnable
Different aims, similar best practices from production code
Unit testing is not optional
Maintainable UTs go down to coupling
References
Code Simplicity - Max Kanat-Alexander
The Art of Unit Testing - Roy Osherove
Culture Code
https://blog.cleancoder.com/uncle-bob/2017/10/03/TestContravariance.html
https://hackernoon.com/how-to-deal-with-test-and-production-code-
c64acd9a062
https://painlessdesign.wordpress.com/2015/06/27/how-to-avoid-fragile-unit-
tests/
https://www.developer.com/tech/5-simple-tips-to-more-robust-unit-tests.html
https://enterprisecraftsmanship.com/posts/unit-testing-private-methods/
Treat your unit tests as production code
Sandor DARGO (Amadeus)
17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 40

More Related Content

What's hot

Cas2010 is-there-space-for-testers-in-agile-projects
Cas2010 is-there-space-for-testers-in-agile-projectsCas2010 is-there-space-for-testers-in-agile-projects
Cas2010 is-there-space-for-testers-in-agile-projectsAgile Spain
 
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationJust Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationDaniel Wildt
 
Developer in Test (SDET) - Job in London
Developer in Test (SDET) - Job in LondonDeveloper in Test (SDET) - Job in London
Developer in Test (SDET) - Job in LondonMark Long
 
Continuous delivery its not about the technology, its about the people. @pipe...
Continuous delivery its not about the technology, its about the people. @pipe...Continuous delivery its not about the technology, its about the people. @pipe...
Continuous delivery its not about the technology, its about the people. @pipe...Tomas Riha
 
A journey to_be_a_software_craftsman
A journey to_be_a_software_craftsmanA journey to_be_a_software_craftsman
A journey to_be_a_software_craftsmanJaehoon Oh
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 
Estado del testing 2019
Estado del testing 2019  Estado del testing 2019
Estado del testing 2019 TestingCR
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkPeter Kofler
 
How to Add Test Automation to your Quality Assurance Toolbelt
How to Add Test Automation to your Quality Assurance ToolbeltHow to Add Test Automation to your Quality Assurance Toolbelt
How to Add Test Automation to your Quality Assurance ToolbeltBrett Tramposh
 
Tdd practices
Tdd practicesTdd practices
Tdd practicesaxykim00
 

What's hot (20)

Cas2010 is-there-space-for-testers-in-agile-projects
Cas2010 is-there-space-for-testers-in-agile-projectsCas2010 is-there-space-for-testers-in-agile-projects
Cas2010 is-there-space-for-testers-in-agile-projects
 
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test AutomationJust Java2007 - Daniel Wildt - Tools For Java Test Automation
Just Java2007 - Daniel Wildt - Tools For Java Test Automation
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
 
TDD = bra design?
TDD = bra design?TDD = bra design?
TDD = bra design?
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
 
Developer in Test (SDET) - Job in London
Developer in Test (SDET) - Job in LondonDeveloper in Test (SDET) - Job in London
Developer in Test (SDET) - Job in London
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
 
Continuous delivery its not about the technology, its about the people. @pipe...
Continuous delivery its not about the technology, its about the people. @pipe...Continuous delivery its not about the technology, its about the people. @pipe...
Continuous delivery its not about the technology, its about the people. @pipe...
 
Tdd
TddTdd
Tdd
 
Tdd
TddTdd
Tdd
 
A journey to_be_a_software_craftsman
A journey to_be_a_software_craftsmanA journey to_be_a_software_craftsman
A journey to_be_a_software_craftsman
 
Five Flute Overview
Five Flute OverviewFive Flute Overview
Five Flute Overview
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Estado del testing 2019
Estado del testing 2019  Estado del testing 2019
Estado del testing 2019
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
How to Add Test Automation to your Quality Assurance Toolbelt
How to Add Test Automation to your Quality Assurance ToolbeltHow to Add Test Automation to your Quality Assurance Toolbelt
How to Add Test Automation to your Quality Assurance Toolbelt
 
Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
 
Tdd
TddTdd
Tdd
 

Similar to Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test Logiciel Sophia 2019

Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionPyxis Technologies
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...mCloud
 
Creating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran KinsbrunerCreating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran KinsbrunerQA or the Highway
 
Branching and Merging Practices
Branching and Merging Practices Branching and Merging Practices
Branching and Merging Practices Rajesh Kumar
 
Test Driven Development: Part 2
Test Driven Development: Part 2Test Driven Development: Part 2
Test Driven Development: Part 2CodeAndroid
 
Agile Testing Pasadena JUG Aug2009
Agile Testing Pasadena JUG Aug2009Agile Testing Pasadena JUG Aug2009
Agile Testing Pasadena JUG Aug2009Grig Gheorghiu
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
Visual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersVisual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersSteve Lange
 
When develpment met test(shift left testing)
When develpment met test(shift left testing)When develpment met test(shift left testing)
When develpment met test(shift left testing)SangIn Choung
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 

Similar to Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test Logiciel Sophia 2019 (20)

TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Google test training
Google test trainingGoogle test training
Google test training
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
 
Creating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran KinsbrunerCreating a successful continuous testing environment by Eran Kinsbruner
Creating a successful continuous testing environment by Eran Kinsbruner
 
Branching and Merging Practices
Branching and Merging Practices Branching and Merging Practices
Branching and Merging Practices
 
Test Driven Development: Part 2
Test Driven Development: Part 2Test Driven Development: Part 2
Test Driven Development: Part 2
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Agile Testing Pasadena JUG Aug2009
Agile Testing Pasadena JUG Aug2009Agile Testing Pasadena JUG Aug2009
Agile Testing Pasadena JUG Aug2009
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Visual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersVisual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for Developers
 
When develpment met test(shift left testing)
When develpment met test(shift left testing)When develpment met test(shift left testing)
When develpment met test(shift left testing)
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
AAA Automated Testing
AAA Automated TestingAAA Automated Testing
AAA Automated Testing
 

More from TelecomValley

Rapport d'activité SoFAB 2022
Rapport d'activité SoFAB 2022Rapport d'activité SoFAB 2022
Rapport d'activité SoFAB 2022TelecomValley
 
Rapport d'activité 2022
Rapport d'activité 2022Rapport d'activité 2022
Rapport d'activité 2022TelecomValley
 
Rapport d'activité 2021 - Telecom Valley
Rapport d'activité 2021 - Telecom ValleyRapport d'activité 2021 - Telecom Valley
Rapport d'activité 2021 - Telecom ValleyTelecomValley
 
Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...
Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...
Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...TelecomValley
 
Rapport d'activité SoFAB 2020
Rapport d'activité SoFAB 2020Rapport d'activité SoFAB 2020
Rapport d'activité SoFAB 2020TelecomValley
 
Rapport d'activité Telecom Valley 2020
Rapport d'activité Telecom Valley 2020Rapport d'activité Telecom Valley 2020
Rapport d'activité Telecom Valley 2020TelecomValley
 
Rapport d'activité SoFAB 2019
Rapport d'activité SoFAB 2019Rapport d'activité SoFAB 2019
Rapport d'activité SoFAB 2019TelecomValley
 
Rapport d'activité Telecom Valley 2019
Rapport d'activité Telecom Valley 2019Rapport d'activité Telecom Valley 2019
Rapport d'activité Telecom Valley 2019TelecomValley
 
Revue de presse Telecom Valley - Février 2020
Revue de presse Telecom Valley - Février 2020Revue de presse Telecom Valley - Février 2020
Revue de presse Telecom Valley - Février 2020TelecomValley
 
Revue de presse Telecom Valley - Janvier 2020
Revue de presse Telecom Valley - Janvier 2020Revue de presse Telecom Valley - Janvier 2020
Revue de presse Telecom Valley - Janvier 2020TelecomValley
 
Revue de presse Telecom Valley - Décembre 2019
Revue de presse Telecom Valley - Décembre 2019Revue de presse Telecom Valley - Décembre 2019
Revue de presse Telecom Valley - Décembre 2019TelecomValley
 
Revue de presse Telecom Valley - Novembre 2019
Revue de presse Telecom Valley - Novembre 2019Revue de presse Telecom Valley - Novembre 2019
Revue de presse Telecom Valley - Novembre 2019TelecomValley
 
Revue de presse Telecom Valley - Octobre 2019
Revue de presse Telecom Valley - Octobre 2019Revue de presse Telecom Valley - Octobre 2019
Revue de presse Telecom Valley - Octobre 2019TelecomValley
 
Revue de presse Telecom Valley - Septembre 2019
Revue de presse Telecom Valley - Septembre 2019Revue de presse Telecom Valley - Septembre 2019
Revue de presse Telecom Valley - Septembre 2019TelecomValley
 
Présentation Team France Export régionale - 29/11/19
Présentation Team France Export régionale - 29/11/19Présentation Team France Export régionale - 29/11/19
Présentation Team France Export régionale - 29/11/19TelecomValley
 
2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...
2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...
2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...TelecomValley
 
Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...
Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...
Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...TelecomValley
 
Et si mon test était la spécification de mon application ? - JACOB - iWE - So...
Et si mon test était la spécification de mon application ? - JACOB - iWE - So...Et si mon test était la spécification de mon application ? - JACOB - iWE - So...
Et si mon test était la spécification de mon application ? - JACOB - iWE - So...TelecomValley
 
A la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFE
A la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFEA la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFE
A la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFETelecomValley
 
2019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.1
2019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.12019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.1
2019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.1TelecomValley
 

More from TelecomValley (20)

Rapport d'activité SoFAB 2022
Rapport d'activité SoFAB 2022Rapport d'activité SoFAB 2022
Rapport d'activité SoFAB 2022
 
Rapport d'activité 2022
Rapport d'activité 2022Rapport d'activité 2022
Rapport d'activité 2022
 
Rapport d'activité 2021 - Telecom Valley
Rapport d'activité 2021 - Telecom ValleyRapport d'activité 2021 - Telecom Valley
Rapport d'activité 2021 - Telecom Valley
 
Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...
Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...
Livre blanc "Les métamorphoses de l'entreprise face à l'imprévu - Tome 1 : la...
 
Rapport d'activité SoFAB 2020
Rapport d'activité SoFAB 2020Rapport d'activité SoFAB 2020
Rapport d'activité SoFAB 2020
 
Rapport d'activité Telecom Valley 2020
Rapport d'activité Telecom Valley 2020Rapport d'activité Telecom Valley 2020
Rapport d'activité Telecom Valley 2020
 
Rapport d'activité SoFAB 2019
Rapport d'activité SoFAB 2019Rapport d'activité SoFAB 2019
Rapport d'activité SoFAB 2019
 
Rapport d'activité Telecom Valley 2019
Rapport d'activité Telecom Valley 2019Rapport d'activité Telecom Valley 2019
Rapport d'activité Telecom Valley 2019
 
Revue de presse Telecom Valley - Février 2020
Revue de presse Telecom Valley - Février 2020Revue de presse Telecom Valley - Février 2020
Revue de presse Telecom Valley - Février 2020
 
Revue de presse Telecom Valley - Janvier 2020
Revue de presse Telecom Valley - Janvier 2020Revue de presse Telecom Valley - Janvier 2020
Revue de presse Telecom Valley - Janvier 2020
 
Revue de presse Telecom Valley - Décembre 2019
Revue de presse Telecom Valley - Décembre 2019Revue de presse Telecom Valley - Décembre 2019
Revue de presse Telecom Valley - Décembre 2019
 
Revue de presse Telecom Valley - Novembre 2019
Revue de presse Telecom Valley - Novembre 2019Revue de presse Telecom Valley - Novembre 2019
Revue de presse Telecom Valley - Novembre 2019
 
Revue de presse Telecom Valley - Octobre 2019
Revue de presse Telecom Valley - Octobre 2019Revue de presse Telecom Valley - Octobre 2019
Revue de presse Telecom Valley - Octobre 2019
 
Revue de presse Telecom Valley - Septembre 2019
Revue de presse Telecom Valley - Septembre 2019Revue de presse Telecom Valley - Septembre 2019
Revue de presse Telecom Valley - Septembre 2019
 
Présentation Team France Export régionale - 29/11/19
Présentation Team France Export régionale - 29/11/19Présentation Team France Export régionale - 29/11/19
Présentation Team France Export régionale - 29/11/19
 
2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...
2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...
2019 - NOURI - ALL4TEST- Le BDD pour decouvrir et specifier les besoins metie...
 
Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...
Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...
Tester c'est bien, monitorer c'est mieux - 2019 - KISSI - Soirée du Test Logi...
 
Et si mon test était la spécification de mon application ? - JACOB - iWE - So...
Et si mon test était la spécification de mon application ? - JACOB - iWE - So...Et si mon test était la spécification de mon application ? - JACOB - iWE - So...
Et si mon test était la spécification de mon application ? - JACOB - iWE - So...
 
A la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFE
A la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFEA la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFE
A la poursuite du bug perdu - 2019 - THEAULT - DI GIORGIO - ACPQUALIFE
 
2019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.1
2019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.12019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.1
2019 - HAGE CHAHINE - ALTRAN - Presentation-DecouverteMondeAgile_V1.1
 

Recently uploaded

Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...amrabdallah9
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical SensorTanvir Moin
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Amil baba
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technologyabdulkadirmukarram03
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderjuancarlos286641
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxrealme6igamerr
 
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Amil baba
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxjasonsedano2
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfJulia Kaye
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Design of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxDesign of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxYogeshKumarKJMIT
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfNaveenVerma126
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsYusuf Yıldız
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS Bahzad5
 
Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingMarian Marinov
 
A Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationA Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationMohsinKhanA
 
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Sean Meyn
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide LaboratoryBahzad5
 

Recently uploaded (20)

Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
 
Basic Principle of Electrochemical Sensor
Basic Principle of  Electrochemical SensorBasic Principle of  Electrochemical Sensor
Basic Principle of Electrochemical Sensor
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technology
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entender
 
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptxUNIT4_ESD_wfffffggggggggggggith_ARM.pptx
UNIT4_ESD_wfffffggggggggggggith_ARM.pptx
 
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptx
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Design of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptxDesign of Clutches and Brakes in Design of Machine Elements.pptx
Design of Clutches and Brakes in Design of Machine Elements.pptx
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovations
 
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS GENERAL CONDITIONS  FOR  CONTRACTS OF CIVIL ENGINEERING WORKS
GENERAL CONDITIONS FOR CONTRACTS OF CIVIL ENGINEERING WORKS
 
Lecture 2 .pdf
Lecture 2                           .pdfLecture 2                           .pdf
Lecture 2 .pdf
 
Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & Logging
 
A Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software SimulationA Seminar on Electric Vehicle Software Simulation
A Seminar on Electric Vehicle Software Simulation
 
Présentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdfPrésentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdf
 
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
 
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratoryدليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
دليل تجارب الاسفلت المختبرية - Asphalt Experiments Guide Laboratory
 

Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test Logiciel Sophia 2019

  • 1. Treat your unit tests as production code Sandor DARGO (Amadeus) 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 1
  • 2. Merci aux Sponsors ! 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 2
  • 3. Agenda Define unit tests You and unit tests Test vs Production code Problems with unit tests Some solutions (no silver bullet) Conclusion 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 3
  • 4. Who am I? Sándor DARGÓ Software developer in Amadeus Enthusiastic blogger http://sandordargo.com Passionate traveller Curious home baker and cook (@sourdad.baker) Happy father of two 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 4
  • 5. What is a unit test? - Automated and repeatable - Written in the language of the code - Exercises a small part of the program (a unit) Ideally, they are - Independent - Isolated 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 5
  • 6. What is a (good) unit test? “A unit test is a piece of code that invokes a unit of work and checks one specific end result of that unit of work. If the assumptions on the end result turn out to be wrong, the unit test has failed. A unit test’s scope can span as little as a method or as much as multiple classes.” - The Art of Unit Testing by Roy Osherove 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 6
  • 7. Are you confident in your unit test suite? Are they all green? Are they all executed? Do they all assert something? Do they all assert something meaningful? Do they all assert a single logical thing? Are they maintained? Do you delete unit tests? How frequently do you have to update them? 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 7
  • 8. Differences between test and production code
  • 9. Differences between test and production code Form groups You have 10 minutes to collect them
  • 10. The pessimist realistic “Production code is written in a hurry and is most often tested by users because there wasn't time for QA and you were under pressure to release. Who gets time to write test code?”
  • 11. Different “raison d’etre” “Production code is is written to be robust (ideally, but not always the case).” “Test code is written just as a poc (proof of concept).” “The difference is in purposes. Production code is for fulfilling the contract. Test code is for verify this contract.” 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 11
  • 12. Some more technical differences “Production code is DRY vs test code is WET.” “Production code is generic vs test code is specific” “Production code has to be fast enough, test code must be super fast.”
  • 13. A tool for write production code and documentation “Production code is only what is necessary to get the test code to pass. And then refactored to make it clean.” “Test code is easily readable and rather blunt. When someone wants to know how the system works, you should be able to point them to the tests that prove the functionality.”
  • 14. What is common in the previous answers? Tests are specific They document something Production behaviour Contract No mention of poor architecture, poor coding practices. Except for the WET part.
  • 15. Why are those differences? The rest makes sense: Differences in purposes Not in implementation details Do we have a good reason to have worse quality?
  • 17. Collect your challenges Form groups You have 10 minutes to collect them
  • 18. Common problems with test code Show its value Dependency injection What to test? (public vs private; GUI) Target code coverage? Does it matter? TDD or not, test first or not? Unit test vs integration test? Test legacy code Mocking
  • 19. Common problems with test code Missing assertions Multiple assertions Tests invoking other tests Logic inside test code Lack of coverage Slowness (DB, I/O access) Dependency between tests Coupling, fragile test code
  • 20. Common problems with test code We have to write them External dependencies Fragile test code
  • 21. Tests? Like production! You have to write them!
  • 22. Is it optional? Client doesn’t want to pay for it? Manager doesn’t want it? Don’t know how to write it?
  • 24. External dependencies Cannot instantiate code under test Non-deterministic results Slow execution time
  • 25. Cut the external dependencies DB and IO operations make tests Dependent Non-deterministic Error-prone Slow
  • 26. The banana, monkey, jungle problem “The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.”
  • 27. Code example Welcome to the jungle! class Alarm { public: Alarm(); void check(); bool isAlarmOn(); protected: Sensor m_sensor; double m_lowPressureTreshold, m_highPressureTreshold; bool m_alarmOn; }; double Sensor::popNextPressurePsiValue() { return random();} Bring your own device class Alarm { public: Alarm(Sensor* sensor, double lowP, double highP); void check(); bool isAlarmOn(); protected: Sensor* m_sensor; double m_lowPressureTreshold, m_highPressureTreshold; bool m_alarmOn; };
  • 29. Do you have the Fragile Test Problem? Test code is highly coupled to production code If code changes, tests are broken Cannot refactor
  • 30. We must keep refactoring Refactoring is part of TDD Adding tests after the fact will also require refactoring
  • 31. What happens when you refactor? class SUT: def operation_a(): pass def operation_b(): pass class TestSUT(unittest.TestCase): def test_operation_a(): pass def test_operation_b(): pass
  • 32. What happens when you refactor? class SUT: def operation_a(): pass def sub_operation_a(): pass def operation_b(): pass def sub_operation_b(): pass class TestSUT(unittest.TestCase): def test_operation_a(): pass def test_operation_b(): pass def test_sub_operation_a(): pass def test_sub_operation_b(): pass
  • 33. What happens when you refactor? class SUT: def operation_a(): pass def operation_b(): pass def sub_operation_a(): pass def sub_operation_b(): pas def common_sub_operation(): pass class TestSUT(unittest.TestCase): def test_operation_a(): pass def test_operation_b(): pass def test_sub_operation_a(): pass def test_sub_operation_b(): pass def test_common_sub_operation(): pass
  • 34. What happens when you refactor? class SUT(CommonSUT): def operation_a(): pass def operation_b(): pass def common_sub_operation(): pass class CommonSUT: def sub_operation(): pass class TestSUT(unittest.TestCase): def test_operation_a(): pass def test_operation_b(): pass def test_common_sub_operation(): pass class TestCommonSUT(unittest.TestCase): def test_sub_operation(): pass
  • 35. Test contravariance “The structure of your tests should not be a mirror of the structure of your code. The fact that you have a class named X should not automatically imply that you have a test class named XTest.” - Uncle Bob
  • 36. What else can you do? Test behavior Don’t mimic production code structure Let test code evolve on its own
  • 37. Don’t be a micromanager Should we test private? No, only the API Should we test every single aspect? Don’t test every bits of implementation
  • 38. Conclusion Unit testing is difficult, but learnable Different aims, similar best practices from production code Unit testing is not optional Maintainable UTs go down to coupling
  • 39. References Code Simplicity - Max Kanat-Alexander The Art of Unit Testing - Roy Osherove Culture Code https://blog.cleancoder.com/uncle-bob/2017/10/03/TestContravariance.html https://hackernoon.com/how-to-deal-with-test-and-production-code- c64acd9a062 https://painlessdesign.wordpress.com/2015/06/27/how-to-avoid-fragile-unit- tests/ https://www.developer.com/tech/5-simple-tips-to-more-robust-unit-tests.html https://enterprisecraftsmanship.com/posts/unit-testing-private-methods/
  • 40. Treat your unit tests as production code Sandor DARGO (Amadeus) 17/10/19 3ème édition Soirée du Test Logiciel Sophia #STLS2019 40