SlideShare a Scribd company logo
1 of 53
@RoyOsherove
What I do (artOfUnitTesting.com)
 Courses on TDD, BDD in JS, Ruby, Java
 and C# TDD (EpiServer TDD, MVC TDD…)
 Courses for Team Leaders (5whys.com)
 Consulting & coaching through Bouvet

 Contact.osherove.com




              Team Agile - All rights
Real World Agenda
 Test Reviews

 Making your tests TRUSTworthy
 Creating MAINTAINable tests
 READable tests
                                 RTFM
Test review vs. code review
 Understand intent of developer
 10 times quicker
 Drill in when needed

 Important for learning teams
 Helps drive change
Readable             Maintainable




           Trustworthy
Make Your tests trust worthy
 Make it easy to run
 Removing or changing tests
 Assuring code coverage
 Avoid test logic
 Avoid Manual StubMock Logic
 Don’t Repeat Production Logic
Separate Unit From Integration Tests
Code coverage?
 Worthless without a code review
 Change production code and see what happens

 Make params into consts
 Remove “if” checks – or make into consts

 If all tests pass - something is missing or something is
 not needed
Avoid test logic (MS Unity)
Another logic example:
MVCDev.HtmlHelperTest.GetHttpContext()
Don’t repeat production logic
  String user = “a”;
  String password= “b”;

 String SomeResult =
 UnderTest.CreateMessage(user,password);

  Assert.AreEqual( user + “,” + password,
                  SomeResult);
Don't use things that keep changing
 DateTime.Now
 Random
 Environment.TickCount
 Threads
 Etc..
Tests that keep changing:
NerdDinner
Creating maintainable tests
 Avoid testing private/protected members
 Re-use test code (Create, Manipulate, Assert)
 Enforce test isolation
 Test One Thing
    Avoid Multiple Asserts
    One mock per test
 Use “relaxed” or “Non strict” mocks and stubs
Test only publics
 “Unit” testing == “Unit Of Work Testing”
 Testing a private makes your test more brittle
 Makes you think about the design and usability
 of a feature
 Test-First leads to private members after
 Refactoring, but they are all tested!

 But sometimes there’s not choice
Reuse test code

 Create objects using common methods
 (factories)
    [make_XX]
 Manipulate and configure initial state using
 common methods
    [init_XX]
 Run common tests in common methods
    [verify_XX]
Enforce test isolation
 No dependency between tests!
 Don’t run a test from another test!
 Run alone
 or all together
 in any order
 Otherwise – leads to nasty “what was that?”
 bugs
Avoid Multiple Asserts On different objects
  String user = “a”;
  String password= “b”;

  String SomeResult =
  UnderTest.CreateMessage(user,password);


  Assert.AreEqual( user + “,” + password, SomeResult);

  Assert.AreEqual (1,UnderTest.MessageCount);
Avoid Multiple Asserts
MVCDev.LinkExtensionsTest L. 334
Avoid Multiple Asserts
 Like having multiple tests
 But the first the fails – kills the others
 You won’t get the big picture (some symptoms)
 Hard to name
 Can lead to more debugging work
Avoid Multiple Mocks
Creating readable tests
 Structure
 No Magic values
    In test
    In mockstub
 Naming a unit test
 Naming variables
 Separate Assert from action
Structure
 Are the tests easy to find?
 Can you find a test for a
 class, or a method?
Setup Mystery
Bad Naming
No Magic Values
 Assert.AreEqual(1003, calc.Parse(“-1”));


 Int parseResult =
 calc.Parse(NEGATIVE_ILLEGAL_NUMBER);

 Assert.AreEqual(
   NEGATIVE_PARSE_RETURN_CODE,
   parseResult)
Hidden Values
Magic values in Fakes
Magic Values
Unity InjectionMethodFixture
Call it what it is (mockstubfake)
 Most “Mocks” are actually stubs.
 If it can be both, call it “Fake”
Naming a unit test
 Method name
 State under test
 Expected behavior/return value

 Add_LessThanZero_ThrowsException()
 Another angle:
 Add_LessThanZero_ThrowsException2()
Naming
Separate Assert from Action


 Assert is less cluttered
 More readable
 Allows handling the return value if needed
 It’s all about readability
Input Values Should Differ
 X.Divide (1,1)
 X.Divide (1,2)

 X.Check(“1,1”)
 X.Check(“1,2”)
Readable             Maintainable




           Trustworthy
ArtOfUnitTesting.com
Song?
This is a test line
Looks like you’re doing fine
Time for a song of mine
Hello DB My Old Friend
Hellow DB my old friend
 I need to work with you again

 That stored procedure ain’t working well
 Whoever wrote that trigger should go to jail

 And that index , it is slower than a snail
 What the hell?
 I guess it’s time…
FOR VIOLENCE
Man, whoever wrote this code
That bastard’s gonna hit the road

Now the customer is gonna sue
Instead of red, my face is turning blue

And it seems like there is no way out of this.
There’s just a hiss.

I guess it’s time, for violence..
I’m angry and I want a name

That DBA should be ashamed
What’s that you’re saying?
It’s ME to blame?

That database was my own sick game?
Oh that’s right.
It was me who did the design

It was mine.
I guess it’s time…
FOR SILENCE.
Thank You

 royo@bouvet.no

 Coaching, mentoring and training
 For team leaders, developers, architects and
 product owners

More Related Content

What's hot

Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleVodqaBLR
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingJoe Tremblay
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)Mani Kanth
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)Peter Thomas
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingRoman Liubun
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkinArati Joshi
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
Asp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxAsp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxRenier Serven
 
Ppt of soap ui
Ppt of soap uiPpt of soap ui
Ppt of soap uipkslide28
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testingpriya_trivedi
 
DevOps, from inception to conclusion
DevOps, from inception to conclusionDevOps, from inception to conclusion
DevOps, from inception to conclusionAbhishek Gaurav
 

What's hot (20)

Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made Simple
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)
 
Spring boot
Spring bootSpring boot
Spring boot
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
Lombok
LombokLombok
Lombok
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Asp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxAsp.Net MVC - Razor Syntax
Asp.Net MVC - Razor Syntax
 
Ppt of soap ui
Ppt of soap uiPpt of soap ui
Ppt of soap ui
 
10 Benefits of Automated Testing
10 Benefits of Automated Testing10 Benefits of Automated Testing
10 Benefits of Automated Testing
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testing
 
DevOps, from inception to conclusion
DevOps, from inception to conclusionDevOps, from inception to conclusion
DevOps, from inception to conclusion
 
Automation Concepts
Automation ConceptsAutomation Concepts
Automation Concepts
 
Testing Tools
Testing ToolsTesting Tools
Testing Tools
 

Viewers also liked

A second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft SwitA second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft SwitRoy Osherove
 
Organizational influence-hacks-45min
Organizational influence-hacks-45minOrganizational influence-hacks-45min
Organizational influence-hacks-45minRoy Osherove
 
Vim - for newbies, by Roy Osherove
Vim - for newbies, by Roy OsheroveVim - for newbies, by Roy Osherove
Vim - for newbies, by Roy OsheroveRoy Osherove
 
Roy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove
 
Team leadership in the age of Agile - Roy Osherove
Team leadership in the age of Agile  - Roy OsheroveTeam leadership in the age of Agile  - Roy Osherove
Team leadership in the age of Agile - Roy OsheroveRoy Osherove
 
Building out a Microservices Architecture with WebSphere Liberty Profile and ...
Building out a Microservices Architecture with WebSphere Liberty Profile and ...Building out a Microservices Architecture with WebSphere Liberty Profile and ...
Building out a Microservices Architecture with WebSphere Liberty Profile and ...David Currie
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'tsPekka Klärck
 

Viewers also liked (9)

A second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft SwitA second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft Swit
 
Organizational influence-hacks-45min
Organizational influence-hacks-45minOrganizational influence-hacks-45min
Organizational influence-hacks-45min
 
Vim - for newbies, by Roy Osherove
Vim - for newbies, by Roy OsheroveVim - for newbies, by Roy Osherove
Vim - for newbies, by Roy Osherove
 
Roy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove TDD From Scratch
Roy Osherove TDD From Scratch
 
Team leadership in the age of Agile - Roy Osherove
Team leadership in the age of Agile  - Roy OsheroveTeam leadership in the age of Agile  - Roy Osherove
Team leadership in the age of Agile - Roy Osherove
 
Building out a Microservices Architecture with WebSphere Liberty Profile and ...
Building out a Microservices Architecture with WebSphere Liberty Profile and ...Building out a Microservices Architecture with WebSphere Liberty Profile and ...
Building out a Microservices Architecture with WebSphere Liberty Profile and ...
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'ts
 

Similar to Roy Osherove on Unit Testing Good Practices and Horrible Mistakes

Automation test
Automation testAutomation test
Automation testyuyijq
 
Practical unit testing tips
Practical unit testing tipsPractical unit testing tips
Practical unit testing tipsTypemock
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfEric Selje
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentDhaval Dalal
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityVictor Rentea
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And DrupalPeter Arato
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in DjangoLoek van Gent
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfEric Selje
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
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
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide vitalipe
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Gianluca Padovani
 

Similar to Roy Osherove on Unit Testing Good Practices and Horrible Mistakes (20)

Automation test
Automation testAutomation test
Automation test
 
Practical unit testing tips
Practical unit testing tipsPractical unit testing tips
Practical unit testing tips
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of Purity
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
Testing 101
Testing 101Testing 101
Testing 101
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in Django
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
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
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
 

Recently uploaded

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Roy Osherove on Unit Testing Good Practices and Horrible Mistakes

  • 2. What I do (artOfUnitTesting.com) Courses on TDD, BDD in JS, Ruby, Java and C# TDD (EpiServer TDD, MVC TDD…) Courses for Team Leaders (5whys.com) Consulting & coaching through Bouvet Contact.osherove.com Team Agile - All rights
  • 3. Real World Agenda Test Reviews Making your tests TRUSTworthy Creating MAINTAINable tests READable tests RTFM
  • 4. Test review vs. code review Understand intent of developer 10 times quicker Drill in when needed Important for learning teams Helps drive change
  • 5. Readable Maintainable Trustworthy
  • 6. Make Your tests trust worthy Make it easy to run Removing or changing tests Assuring code coverage Avoid test logic Avoid Manual StubMock Logic Don’t Repeat Production Logic
  • 7. Separate Unit From Integration Tests
  • 8. Code coverage? Worthless without a code review Change production code and see what happens Make params into consts Remove “if” checks – or make into consts If all tests pass - something is missing or something is not needed
  • 9. Avoid test logic (MS Unity)
  • 11. Don’t repeat production logic String user = “a”; String password= “b”; String SomeResult = UnderTest.CreateMessage(user,password); Assert.AreEqual( user + “,” + password, SomeResult);
  • 12. Don't use things that keep changing DateTime.Now Random Environment.TickCount Threads Etc..
  • 13. Tests that keep changing: NerdDinner
  • 14. Creating maintainable tests Avoid testing private/protected members Re-use test code (Create, Manipulate, Assert) Enforce test isolation Test One Thing Avoid Multiple Asserts One mock per test Use “relaxed” or “Non strict” mocks and stubs
  • 15. Test only publics “Unit” testing == “Unit Of Work Testing” Testing a private makes your test more brittle Makes you think about the design and usability of a feature Test-First leads to private members after Refactoring, but they are all tested! But sometimes there’s not choice
  • 16. Reuse test code Create objects using common methods (factories) [make_XX] Manipulate and configure initial state using common methods [init_XX] Run common tests in common methods [verify_XX]
  • 17. Enforce test isolation No dependency between tests! Don’t run a test from another test! Run alone or all together in any order Otherwise – leads to nasty “what was that?” bugs
  • 18. Avoid Multiple Asserts On different objects String user = “a”; String password= “b”; String SomeResult = UnderTest.CreateMessage(user,password); Assert.AreEqual( user + “,” + password, SomeResult); Assert.AreEqual (1,UnderTest.MessageCount);
  • 19.
  • 21.
  • 22. Avoid Multiple Asserts Like having multiple tests But the first the fails – kills the others You won’t get the big picture (some symptoms) Hard to name Can lead to more debugging work
  • 24. Creating readable tests Structure No Magic values In test In mockstub Naming a unit test Naming variables Separate Assert from action
  • 25. Structure Are the tests easy to find? Can you find a test for a class, or a method?
  • 28. No Magic Values Assert.AreEqual(1003, calc.Parse(“-1”)); Int parseResult = calc.Parse(NEGATIVE_ILLEGAL_NUMBER); Assert.AreEqual( NEGATIVE_PARSE_RETURN_CODE, parseResult)
  • 31.
  • 33. Call it what it is (mockstubfake) Most “Mocks” are actually stubs. If it can be both, call it “Fake”
  • 34. Naming a unit test Method name State under test Expected behavior/return value Add_LessThanZero_ThrowsException() Another angle: Add_LessThanZero_ThrowsException2()
  • 36. Separate Assert from Action Assert is less cluttered More readable Allows handling the return value if needed It’s all about readability
  • 37. Input Values Should Differ X.Divide (1,1) X.Divide (1,2) X.Check(“1,1”) X.Check(“1,2”)
  • 38. Readable Maintainable Trustworthy
  • 40. Song?
  • 41. This is a test line
  • 42. Looks like you’re doing fine
  • 43. Time for a song of mine
  • 44. Hello DB My Old Friend
  • 45. Hellow DB my old friend I need to work with you again That stored procedure ain’t working well Whoever wrote that trigger should go to jail And that index , it is slower than a snail What the hell? I guess it’s time…
  • 47. Man, whoever wrote this code That bastard’s gonna hit the road Now the customer is gonna sue Instead of red, my face is turning blue And it seems like there is no way out of this.
  • 48. There’s just a hiss. I guess it’s time, for violence..
  • 49. I’m angry and I want a name That DBA should be ashamed
  • 50. What’s that you’re saying? It’s ME to blame? That database was my own sick game?
  • 51. Oh that’s right. It was me who did the design It was mine. I guess it’s time…
  • 53. Thank You royo@bouvet.no Coaching, mentoring and training For team leaders, developers, architects and product owners