SlideShare a Scribd company logo
1 of 19
Raising the Value of Your
Unit Tests
Richard Taylor
Vice President of Platform and Cloud Engineering
SentryOne – http://www.sentryone.com
@rightincode – http://www.rightincode.com
Who is Richard Taylor?
Full Stack Software Engineer
Lives in Huntersville, NC
Organizer of CLT Xamarin Developers
Lead Organizer of Modern Devs CLT
http://www.rightincode.com
@rightincode
Vice President of Platform and Cloud Engineering
Huntersville, NC
http://www.sentryone.com
@sentryone
@rightincode - http://www.rightincode.com
Goals of this talk
 Define unit testing
 Explore styles of unit tests
 Identify weaknesses in unit tests
 How to increase the value of unit tests
@rightincode - http://www.rightincode.com
What is Unit Testing?
Unit testing is the process of independently
testing the smallest testable part of your
code (unit of work) for proper function
Class (its public interface), individual
method
The target of a unit test is the system
under test (SUT)
A unit test is code (code to test code)
@rightincode - http://www.rightincode.com
What is Unit Testing? – cont.
 While unit testing can be done manually, it is
mostly automated
Local build on your development machine
CI/CD pipeline
 Unit testing should be isolated
testing more complicated scenarios is the
responsibility of integration testing
 Unit testing is not Test Driven Development
(TDD) but a component of TDD
@rightincode - http://www.rightincode.com
Why Write Unit Tests?
 To increase confidence that code changes do
not break existing functionality
 To find errors early
 To provide some documentation
 To help facilitate better software design via
refactoring
@rightincode - http://www.rightincode.com
Styles of Unit Tests
Output Verification
Provide SUT with known input(s) and test for
expected output
Highest value
State Verification
Provide SUT with known inputs(s) or use public
interface and test the state (single or multiple
data points) for expected values
High value
@rightincode - http://www.rightincode.com
Styles of Unit Tests – cont.
Collaboration Verification
Provide known input(s) or use public interface
and test how it interacts with collaborators
Least value compared to output/state
verification but offers some value
Typically brittle and difficult to maintain
@rightincode - http://www.rightincode.com
What is a valuable test?
 Has a high chance of catching a regression bug
 Has a low chance of producing a false positive
 Provides fast feedback
@rightincode - http://www.rightincode.com
What can cause unit test to lose value?
 Test names that do not effectively describe the
test
 Complicated unit test code
 Testing more that a single unit of work
 Brittle to system under test (SUT) code changes
 Difficult to maintain
 Unreliable
 Slow
@rightincode - http://www.rightincode.com
How to make your unit test more
effective/valuable?
 Clear, simple, and readable
 High value
 Flexible
@rightincode - http://www.rightincode.com
Effective Unit Tests – Clear, Simple, and
Readable
 Make test names consistent and meaningful
Utilize a naming convention
i.e. three part naming convention
UnitOfWork_InitialCondition_ExpectedResult
Easy to scan/search
Groups together tests for the same unit of work
Provides some insight into the business rules
@rightincode - http://www.rightincode.com
Effective Unit Tests – Clear, Simple, and
Readable
Test suite should be organized
DRY – Don’t Repeat Yourself
DAMP – Descriptive and Meaningful Phrases
Follow a distinct pattern in your test
Setup/Arrange
Action
Assert
@rightincode - http://www.rightincode.com
Effective Unit Tests – Clear, Simple, and
Readable
Focus on high precision
Test one expectation per test
Multiple assertions on an object is okay but
be careful
A test should point to a precise location of a
problem
@rightincode - http://www.rightincode.com
Effective Unit Tests – High Value
Focus on testable code
Use dependency injection to provide
dependencies
Avoid using "new"; it creates dependencies
Avoid global state
Be careful with static methods
@rightincode - http://www.rightincode.com
Effective Unit Tests – High Value
Focus on testable code – cont’d
Use seams with legacy code
"New" the dependency but provide the
ability to override it and use that ability to
unit test
Favor composition over inheritance
Dependency Injection
Apply SOLID principles
@rightincode - http://www.rightincode.com
Effective Unit Tests – High Value
 Test the code that has high risk
Complex workflows
Calculations
Minimize "What if" scenarios
Cover all business rules
Cover happy and non-happy paths
Avoid testing things the compiler would
catch (types, etc.) and text
@rightincode - http://www.rightincode.com
Effective Unit Tests – Flexible
 Maximum of one mock per test
 Fewer than 10% of your test with mocks
 Do not test private methods
Should be covered by testing other public methods
 Test by scenarios rather than method
@rightincode - http://www.rightincode.com
Resources
 Repo: (code)
 https://github.com/rightincode/Xamarin-Forms-ToDo
Branch: Testability
 Unit Testing
 https://www.toptal.com/qa/how-to-write-testable-code-and-why-it-matters
 Pluralsight
Building a Pragmatic Unit Test Suite
Writing Highly Maintainable Unit Tests
Advance Unit Testing
 Working Effectively with Legacy Code - Michael Feathers
 Beyond Legacy Code - David Bernstein
 Testing Frameworks (.NET)
 Unit testing C# with MSTest and .NET Core
https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest
 Nunit
http://nunit.org/
 Xunit
https://xunit.github.io/
@rightincode - http://www.rightincode.com

More Related Content

What's hot

Test Cases Maintaining & Documenting
Test Cases Maintaining & DocumentingTest Cases Maintaining & Documenting
Test Cases Maintaining & DocumentingSeyed Ali Marjaie
 
Best Practices for Test Case Writing
Best Practices for Test Case WritingBest Practices for Test Case Writing
Best Practices for Test Case WritingSarah Goldberg
 
Testcase definition
Testcase definitionTestcase definition
Testcase definitionOana Feidi
 
Test scenarios for sending & receiving emails
Test scenarios for sending & receiving emailsTest scenarios for sending & receiving emails
Test scenarios for sending & receiving emailsMorpheous Algan
 
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...Ievgenii Katsan
 
Unit 2 - Test Case Design
Unit 2 - Test Case DesignUnit 2 - Test Case Design
Unit 2 - Test Case DesignSelvi Vts
 
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...dcieslak
 
Test Cases Vs Test Scenarios
Test Cases Vs Test ScenariosTest Cases Vs Test Scenarios
Test Cases Vs Test ScenariosSneha Singh
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platformChamil Madusanka
 
Writing Test Cases in Agile
Writing Test Cases in AgileWriting Test Cases in Agile
Writing Test Cases in AgileSaroj Singh
 
Black box Testing by Laraib
Black box Testing by Laraib Black box Testing by Laraib
Black box Testing by Laraib laraibalvi1
 
Test Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh DahalTest Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh DahalQA or the Highway
 
Test Case Naming 02
Test Case Naming 02Test Case Naming 02
Test Case Naming 02SriluBalla
 

What's hot (20)

Test Cases Maintaining & Documenting
Test Cases Maintaining & DocumentingTest Cases Maintaining & Documenting
Test Cases Maintaining & Documenting
 
Best Practices for Test Case Writing
Best Practices for Test Case WritingBest Practices for Test Case Writing
Best Practices for Test Case Writing
 
Testing techniques
Testing techniquesTesting techniques
Testing techniques
 
Test design techniques
Test design techniquesTest design techniques
Test design techniques
 
Testcase definition
Testcase definitionTestcase definition
Testcase definition
 
Test scenarios for sending & receiving emails
Test scenarios for sending & receiving emailsTest scenarios for sending & receiving emails
Test scenarios for sending & receiving emails
 
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
 
Unit 2 - Test Case Design
Unit 2 - Test Case DesignUnit 2 - Test Case Design
Unit 2 - Test Case Design
 
Effective Software Test Case Design Approach
Effective Software Test Case Design ApproachEffective Software Test Case Design Approach
Effective Software Test Case Design Approach
 
Apex Testing Best Practices
Apex Testing Best PracticesApex Testing Best Practices
Apex Testing Best Practices
 
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
 
Test Cases Vs Test Scenarios
Test Cases Vs Test ScenariosTest Cases Vs Test Scenarios
Test Cases Vs Test Scenarios
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
Checklist for website testing
Checklist for website testingChecklist for website testing
Checklist for website testing
 
Writing Test Cases in Agile
Writing Test Cases in AgileWriting Test Cases in Agile
Writing Test Cases in Agile
 
Black box Testing by Laraib
Black box Testing by Laraib Black box Testing by Laraib
Black box Testing by Laraib
 
Test Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh DahalTest Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh Dahal
 
Test cases
Test casesTest cases
Test cases
 
Test Case Naming 02
Test Case Naming 02Test Case Naming 02
Test Case Naming 02
 
Testing
TestingTesting
Testing
 

Similar to Raising the value of your unit tests

Refactoring to Testable Code
Refactoring to Testable CodeRefactoring to Testable Code
Refactoring to Testable CodeRichard Taylor
 
What are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | EdurekaWhat are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | EdurekaEdureka!
 
Automation testing
Automation testingAutomation testing
Automation testingTomy Rhymond
 
Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer Rachid Kherrazi
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSebastian Wagner
 
6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation ArchitectureErdem YILDIRIM
 
Just Enough (Automated) Testing
Just Enough (Automated) TestingJust Enough (Automated) Testing
Just Enough (Automated) TestingSauce Labs
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Automating The Process For Building Reliable Software
Automating The Process For Building Reliable SoftwareAutomating The Process For Building Reliable Software
Automating The Process For Building Reliable Softwareguest8861ff
 
Testing Interview Questions.pdf
Testing Interview Questions.pdfTesting Interview Questions.pdf
Testing Interview Questions.pdfPradeepaKannan6
 
The Automation Firehose: Be Strategic & Tactical With Your Mobile & Web Testing
The Automation Firehose: Be Strategic & Tactical With Your Mobile & Web TestingThe Automation Firehose: Be Strategic & Tactical With Your Mobile & Web Testing
The Automation Firehose: Be Strategic & Tactical With Your Mobile & Web TestingPerfecto by Perforce
 
Testing 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be RequiredTesting 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be RequiredArleneAndrews2
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...
QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...
QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...QAFest
 
Parallel run selenium tests in a good way
Parallel run selenium tests in a good  wayParallel run selenium tests in a good  way
Parallel run selenium tests in a good wayCOMAQA.BY
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-conceptsmedsherb
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Kevin Schultz
 

Similar to Raising the value of your unit tests (20)

Refactoring to Testable Code
Refactoring to Testable CodeRefactoring to Testable Code
Refactoring to Testable Code
 
What are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | EdurekaWhat are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | Edureka
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer Hands-on Experience Model based testing with spec explorer
Hands-on Experience Model based testing with spec explorer
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best Practises
 
6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture
 
Just Enough (Automated) Testing
Just Enough (Automated) TestingJust Enough (Automated) Testing
Just Enough (Automated) Testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Automating The Process For Building Reliable Software
Automating The Process For Building Reliable SoftwareAutomating The Process For Building Reliable Software
Automating The Process For Building Reliable Software
 
Testing Interview Questions.pdf
Testing Interview Questions.pdfTesting Interview Questions.pdf
Testing Interview Questions.pdf
 
The Automation Firehose: Be Strategic & Tactical With Your Mobile & Web Testing
The Automation Firehose: Be Strategic & Tactical With Your Mobile & Web TestingThe Automation Firehose: Be Strategic & Tactical With Your Mobile & Web Testing
The Automation Firehose: Be Strategic & Tactical With Your Mobile & Web Testing
 
Testing 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be RequiredTesting 3: Types Of Tests That May Be Required
Testing 3: Types Of Tests That May Be Required
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...
QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...
QA Fest 2018. Ярослав Пернеровский. Test Automation Pyramid, how it ruins you...
 
Parallel run selenium tests in a good way
Parallel run selenium tests in a good  wayParallel run selenium tests in a good  way
Parallel run selenium tests in a good way
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
 
prova4
prova4prova4
prova4
 
provalast
provalastprovalast
provalast
 
test3
test3test3
test3
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 

Raising the value of your unit tests

  • 1. Raising the Value of Your Unit Tests Richard Taylor Vice President of Platform and Cloud Engineering SentryOne – http://www.sentryone.com @rightincode – http://www.rightincode.com
  • 2. Who is Richard Taylor? Full Stack Software Engineer Lives in Huntersville, NC Organizer of CLT Xamarin Developers Lead Organizer of Modern Devs CLT http://www.rightincode.com @rightincode Vice President of Platform and Cloud Engineering Huntersville, NC http://www.sentryone.com @sentryone @rightincode - http://www.rightincode.com
  • 3. Goals of this talk  Define unit testing  Explore styles of unit tests  Identify weaknesses in unit tests  How to increase the value of unit tests @rightincode - http://www.rightincode.com
  • 4. What is Unit Testing? Unit testing is the process of independently testing the smallest testable part of your code (unit of work) for proper function Class (its public interface), individual method The target of a unit test is the system under test (SUT) A unit test is code (code to test code) @rightincode - http://www.rightincode.com
  • 5. What is Unit Testing? – cont.  While unit testing can be done manually, it is mostly automated Local build on your development machine CI/CD pipeline  Unit testing should be isolated testing more complicated scenarios is the responsibility of integration testing  Unit testing is not Test Driven Development (TDD) but a component of TDD @rightincode - http://www.rightincode.com
  • 6. Why Write Unit Tests?  To increase confidence that code changes do not break existing functionality  To find errors early  To provide some documentation  To help facilitate better software design via refactoring @rightincode - http://www.rightincode.com
  • 7. Styles of Unit Tests Output Verification Provide SUT with known input(s) and test for expected output Highest value State Verification Provide SUT with known inputs(s) or use public interface and test the state (single or multiple data points) for expected values High value @rightincode - http://www.rightincode.com
  • 8. Styles of Unit Tests – cont. Collaboration Verification Provide known input(s) or use public interface and test how it interacts with collaborators Least value compared to output/state verification but offers some value Typically brittle and difficult to maintain @rightincode - http://www.rightincode.com
  • 9. What is a valuable test?  Has a high chance of catching a regression bug  Has a low chance of producing a false positive  Provides fast feedback @rightincode - http://www.rightincode.com
  • 10. What can cause unit test to lose value?  Test names that do not effectively describe the test  Complicated unit test code  Testing more that a single unit of work  Brittle to system under test (SUT) code changes  Difficult to maintain  Unreliable  Slow @rightincode - http://www.rightincode.com
  • 11. How to make your unit test more effective/valuable?  Clear, simple, and readable  High value  Flexible @rightincode - http://www.rightincode.com
  • 12. Effective Unit Tests – Clear, Simple, and Readable  Make test names consistent and meaningful Utilize a naming convention i.e. three part naming convention UnitOfWork_InitialCondition_ExpectedResult Easy to scan/search Groups together tests for the same unit of work Provides some insight into the business rules @rightincode - http://www.rightincode.com
  • 13. Effective Unit Tests – Clear, Simple, and Readable Test suite should be organized DRY – Don’t Repeat Yourself DAMP – Descriptive and Meaningful Phrases Follow a distinct pattern in your test Setup/Arrange Action Assert @rightincode - http://www.rightincode.com
  • 14. Effective Unit Tests – Clear, Simple, and Readable Focus on high precision Test one expectation per test Multiple assertions on an object is okay but be careful A test should point to a precise location of a problem @rightincode - http://www.rightincode.com
  • 15. Effective Unit Tests – High Value Focus on testable code Use dependency injection to provide dependencies Avoid using "new"; it creates dependencies Avoid global state Be careful with static methods @rightincode - http://www.rightincode.com
  • 16. Effective Unit Tests – High Value Focus on testable code – cont’d Use seams with legacy code "New" the dependency but provide the ability to override it and use that ability to unit test Favor composition over inheritance Dependency Injection Apply SOLID principles @rightincode - http://www.rightincode.com
  • 17. Effective Unit Tests – High Value  Test the code that has high risk Complex workflows Calculations Minimize "What if" scenarios Cover all business rules Cover happy and non-happy paths Avoid testing things the compiler would catch (types, etc.) and text @rightincode - http://www.rightincode.com
  • 18. Effective Unit Tests – Flexible  Maximum of one mock per test  Fewer than 10% of your test with mocks  Do not test private methods Should be covered by testing other public methods  Test by scenarios rather than method @rightincode - http://www.rightincode.com
  • 19. Resources  Repo: (code)  https://github.com/rightincode/Xamarin-Forms-ToDo Branch: Testability  Unit Testing  https://www.toptal.com/qa/how-to-write-testable-code-and-why-it-matters  Pluralsight Building a Pragmatic Unit Test Suite Writing Highly Maintainable Unit Tests Advance Unit Testing  Working Effectively with Legacy Code - Michael Feathers  Beyond Legacy Code - David Bernstein  Testing Frameworks (.NET)  Unit testing C# with MSTest and .NET Core https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest  Nunit http://nunit.org/  Xunit https://xunit.github.io/ @rightincode - http://www.rightincode.com

Editor's Notes

  1. *Collaboration Verification: ensuring the SUT is collaborating correctly with its partners by checking that all collaborators were called in the correct order with correct parameters