SlideShare a Scribd company logo
Advanced Unit Testing – real life
examples and mistakes
Milan Vukoje
www.Vukoje.NET
vukoje@gmail.com
 Goals & Dangers
 Real life examples
 VS & TFS tips
 Best Practices
 Smells
Themes
 Improved quality
 SUT understanding
 Reduced risk
 Easy creation/maintaining
 Easy run
Goals of UT
 Additional costs
 Slowing down production code changing
 Losing tests in logic migration
 Tests take too long to write
 Poor Organization /Maintenance problems
Dangers of UT
Soprex Core Application (SCA)
DB
Win Web
UI
BL
DAL
SCRUM
Refactoring
Coding Standard
Code Review
 DB problems
 Persistent
 Slow
 Shared
 Complicated
Persistent fixture
DB
Win Web
UI
BL
DAL
 Shared Fixture + Partial cleanup
 Cleanup in Finally blocks
SCA.DAL – Cleanup Strategy
 Not treating tests as production code
 Do not duplicate test code
 Creation and Finder methods
 Custom Assertations
 Parameterized tests
 Test Run War
SCA.DAL
DB
Win Web
UI
BL
DAL
Database Sandbox
 Generic CRUD tests
 Uses generated values
 Tries to break constraints
 Insert nulls
 Max values
 Mini integration tests
 Great for detecting DB schema mismatch
SCA.BLTester
BL
DAL
DB
BLTester
SCA.BLTester example
SCA.BLTester cleanup
 Isolated Business Logic testing
 Mini Integration vs. FakeDB
 QueryObject + DataTable = FakeDB
 SCA.MockHelper
 Setup with Reflection
 Factory would be better choice
SCA.FakeDB
BL
DAL
DB
Fake DB
 Avoid Fragile Tests (To Pass or Not to Pass)
 Test Run War
 Non- deterministic tests
 Interacting tests
 Don’t use DB accident/random records
 When there is a way of testing w/o the DB,
test w/o DB.
 SCA.AppTranslation
 Testing w/o DB
 And than back to DB…
Lessons Learned
DB
Win Web
UI
BL
DAL
 Very important
 Bug can be very expensive
 Huge num. of combinations
 Integration Test failure
SCA.PriceCalculator
DB
Price Calculator
BL
DAL
Price
Request
Price
 Price Manager
 Simple calculations
 Easily tested with FakeDB
 Highly optimized cache
 Price Calculator
 Main algorithm
 Easily tested with Stub
 Concurrency control
Stub to the rescue!
DB
Price Calculator
BL
DAL
Price
Request
Price
Price Manager
When you have a new hammer, everything looks like a nail!
 Calculator example
 Use the Front Door First
 Guard Assert Example
Overdoing mocking
Use Case testing
DB
Win Web
UI
BL
DAL
 Model – View – Problem
 Presenter testing problems
 Not Isolated (GUI)
 Hard Indirect output control
 Testing Mocks
 Solution
 View Stub
 Setup Methods
SCA.UI
DB
Win Web
UI
BL
DAL
 Design for Testability
 Just a bit design upfront
 Be ware of the code smells
 Keep It Simple and Stupid (KISS)
 Always know what you are testing
Lessons learned
DB
Win Web
UI
BL
DAL
 Minimize untestable code
 Auto-synchronization
 Helper classes
 Indirect GUI control
 Don’t test GUI
 Also… buy GUI controls 
SCA.GUI
DB
Win Web
UI
BL
DAL
 Avoid Accessors
 Do not generate unit tests
 Avoid assertion roulette
 Use Assert class properly
Visual Studio tips
 Test Run & Build Policy
 Check-in Build & Build With Tests
 Nightly build with Code Analysis and Tests
 Build Error Notification
TFS - Continues Integration with
 Write the Tests First
 Communicate Intent
 Do not modify the SUT
 Keep Tests Independent
 Minimize Test Overlap
 Keep Test Logic Out of Production Code
 Verify One Condition per Test
More best practices…
 Design
 Long setup
 Hard to test code
 Slow tests
 Test logic in production
 Code
 Obscure test
 High test maintenance
 Conditional test logic
 Duplication
 Frequent Debugging
 Production bugs
Smells
 UT have grate benefits
 UT comes with dangers
 Watch the smells?
 Follow best practices
Summary
Questions?
Please fill the questionnaire !
You have a chance to win:
Sponsored by:
Thanks!
Milan Vukoje
www.Vukoje.NET
vukoje@gmail.com

More Related Content

PPTX
Real Life Unit Testing
PDF
Test Driven Development
ODP
Mistakes I have made
PPTX
Type mock isolator
PPTX
Test Driven Development
PPTX
Test case writing
PPTX
Unit testing
PPTX
Mixing testing types to improve your testing results
Real Life Unit Testing
Test Driven Development
Mistakes I have made
Type mock isolator
Test Driven Development
Test case writing
Unit testing
Mixing testing types to improve your testing results

What's hot (20)

PPTX
Test Automation Architecture That Works by Bhupesh Dahal
PPTX
xUnit test patterns 0
PPTX
So you think you can write a test case
PPTX
How to write defect
PPTX
An Introduction to Unit Testing
PPTX
Clean code
PPTX
Unit testing
PPTX
An Overview of automated testing (1)
PDF
Unit testing (workshop)
PPTX
Automated tests
PPTX
Mock driven development using .NET
PDF
Sqa, test scenarios and test cases
PPTX
Moq presentation
PPTX
Roy Osherove TDD From Scratch
PDF
Php tests tips
PPTX
An Introduction to unit testing
PPTX
Good Unit Tests Ask For Quality Code
PPS
Test Cases Maintaining & Documenting
PPS
Test case design_the_basicsv0.4
PPTX
Unit testing - the hard parts
Test Automation Architecture That Works by Bhupesh Dahal
xUnit test patterns 0
So you think you can write a test case
How to write defect
An Introduction to Unit Testing
Clean code
Unit testing
An Overview of automated testing (1)
Unit testing (workshop)
Automated tests
Mock driven development using .NET
Sqa, test scenarios and test cases
Moq presentation
Roy Osherove TDD From Scratch
Php tests tips
An Introduction to unit testing
Good Unit Tests Ask For Quality Code
Test Cases Maintaining & Documenting
Test case design_the_basicsv0.4
Unit testing - the hard parts
Ad

Viewers also liked (18)

PPTX
Dan Solovay - Test Driven Sitecore - SUGCON
PDF
User Testing by Example
DOCX
QA Tester Junior
PDF
Agile testing and_the_banking_domain_2009
PDF
Is an agile SDLC an oxymoron?
PDF
Browser-level testing
PDF
Testing of e-Banking - Case Study
PPT
Agile Testing - Challenges
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
PDF
Linking Upstream and Downstream Agile
PDF
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
PDF
Unit-testing and E2E testing in JS
PPTX
The Impact of Big Data On Marketing Analytics (UpStream Software)
PDF
JavaOne 2011: Migrating Spring Applications to Java EE 6
PDF
Software testing methods, levels and types
PPT
Types of Software Testing
PDF
Integration Test Hell
PDF
Software Development 2014: Trends & Benchmarks in Agile, Requirements and Tes...
Dan Solovay - Test Driven Sitecore - SUGCON
User Testing by Example
QA Tester Junior
Agile testing and_the_banking_domain_2009
Is an agile SDLC an oxymoron?
Browser-level testing
Testing of e-Banking - Case Study
Agile Testing - Challenges
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Linking Upstream and Downstream Agile
End-2-End Monitoring – Der Prüfstand jedes SLA´s – in 15 Minuten erklärt!
Unit-testing and E2E testing in JS
The Impact of Big Data On Marketing Analytics (UpStream Software)
JavaOne 2011: Migrating Spring Applications to Java EE 6
Software testing methods, levels and types
Types of Software Testing
Integration Test Hell
Software Development 2014: Trends & Benchmarks in Agile, Requirements and Tes...
Ad

Similar to Advanced unit testing – real life examples and mistakes (20)

PPTX
No More No Repro
PPTX
Microsoft Stack Visual Studio 2010 Overview
PPTX
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
PPTX
Lap Around Visual Studio 2010 Ultimate And TFS 2010
PPT
12 Rational Solo Pruebas 2009
PPTX
Unit Tests And Automated Testing
PPTX
Whats New In 2010 (Msdn & Visual Studio)
PPTX
Application Lifecycle Management with TFS
PPTX
Software Development Practices in Practice
PPTX
Better User Experience with .NET
PPTX
Software Reengineering
PPT
Vsts 2
PPT
Automated Testing vs Manual Testing
PPT
Automated Testing vs Manual Testing
PPT
Automated+Testing+Vs+Manual+Testing
PPT
BJDsolutions.com agile process
PPTX
Full Testing Experience - Visual Studio and TFS 2010
PPTX
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
PPTX
Test driving an MVVM App
PPT
Rhapsody Systems Software
No More No Repro
Microsoft Stack Visual Studio 2010 Overview
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
Lap Around Visual Studio 2010 Ultimate And TFS 2010
12 Rational Solo Pruebas 2009
Unit Tests And Automated Testing
Whats New In 2010 (Msdn & Visual Studio)
Application Lifecycle Management with TFS
Software Development Practices in Practice
Better User Experience with .NET
Software Reengineering
Vsts 2
Automated Testing vs Manual Testing
Automated Testing vs Manual Testing
Automated+Testing+Vs+Manual+Testing
BJDsolutions.com agile process
Full Testing Experience - Visual Studio and TFS 2010
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Test driving an MVVM App
Rhapsody Systems Software

More from Milan Vukoje (6)

PPTX
Juniori/Seniori
PPTX
State of the art logging
PPTX
Code Refactoring
PPTX
Coding Standard And Code Review
PPT
Soprex framework on .net in action
PPTX
Unit testing solid fundamentals
Juniori/Seniori
State of the art logging
Code Refactoring
Coding Standard And Code Review
Soprex framework on .net in action
Unit testing solid fundamentals

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Monthly Chronicles - July 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”

Advanced unit testing – real life examples and mistakes

  • 1. Advanced Unit Testing – real life examples and mistakes Milan Vukoje www.Vukoje.NET vukoje@gmail.com
  • 2.  Goals & Dangers  Real life examples  VS & TFS tips  Best Practices  Smells Themes
  • 3.  Improved quality  SUT understanding  Reduced risk  Easy creation/maintaining  Easy run Goals of UT
  • 4.  Additional costs  Slowing down production code changing  Losing tests in logic migration  Tests take too long to write  Poor Organization /Maintenance problems Dangers of UT
  • 5. Soprex Core Application (SCA) DB Win Web UI BL DAL SCRUM Refactoring Coding Standard Code Review
  • 6.  DB problems  Persistent  Slow  Shared  Complicated Persistent fixture DB Win Web UI BL DAL
  • 7.  Shared Fixture + Partial cleanup  Cleanup in Finally blocks SCA.DAL – Cleanup Strategy
  • 8.  Not treating tests as production code  Do not duplicate test code  Creation and Finder methods  Custom Assertations  Parameterized tests  Test Run War SCA.DAL DB Win Web UI BL DAL
  • 10.  Generic CRUD tests  Uses generated values  Tries to break constraints  Insert nulls  Max values  Mini integration tests  Great for detecting DB schema mismatch SCA.BLTester BL DAL DB BLTester
  • 13.  Isolated Business Logic testing  Mini Integration vs. FakeDB  QueryObject + DataTable = FakeDB  SCA.MockHelper  Setup with Reflection  Factory would be better choice SCA.FakeDB BL DAL DB Fake DB
  • 14.  Avoid Fragile Tests (To Pass or Not to Pass)  Test Run War  Non- deterministic tests  Interacting tests  Don’t use DB accident/random records  When there is a way of testing w/o the DB, test w/o DB.  SCA.AppTranslation  Testing w/o DB  And than back to DB… Lessons Learned DB Win Web UI BL DAL
  • 15.  Very important  Bug can be very expensive  Huge num. of combinations  Integration Test failure SCA.PriceCalculator DB Price Calculator BL DAL Price Request Price
  • 16.  Price Manager  Simple calculations  Easily tested with FakeDB  Highly optimized cache  Price Calculator  Main algorithm  Easily tested with Stub  Concurrency control Stub to the rescue! DB Price Calculator BL DAL Price Request Price Price Manager
  • 17. When you have a new hammer, everything looks like a nail!  Calculator example  Use the Front Door First  Guard Assert Example Overdoing mocking
  • 18. Use Case testing DB Win Web UI BL DAL
  • 19.  Model – View – Problem  Presenter testing problems  Not Isolated (GUI)  Hard Indirect output control  Testing Mocks  Solution  View Stub  Setup Methods SCA.UI DB Win Web UI BL DAL
  • 20.  Design for Testability  Just a bit design upfront  Be ware of the code smells  Keep It Simple and Stupid (KISS)  Always know what you are testing Lessons learned DB Win Web UI BL DAL
  • 21.  Minimize untestable code  Auto-synchronization  Helper classes  Indirect GUI control  Don’t test GUI  Also… buy GUI controls  SCA.GUI DB Win Web UI BL DAL
  • 22.  Avoid Accessors  Do not generate unit tests  Avoid assertion roulette  Use Assert class properly Visual Studio tips
  • 23.  Test Run & Build Policy  Check-in Build & Build With Tests  Nightly build with Code Analysis and Tests  Build Error Notification TFS - Continues Integration with
  • 24.  Write the Tests First  Communicate Intent  Do not modify the SUT  Keep Tests Independent  Minimize Test Overlap  Keep Test Logic Out of Production Code  Verify One Condition per Test More best practices…
  • 25.  Design  Long setup  Hard to test code  Slow tests  Test logic in production  Code  Obscure test  High test maintenance  Conditional test logic  Duplication  Frequent Debugging  Production bugs Smells
  • 26.  UT have grate benefits  UT comes with dangers  Watch the smells?  Follow best practices Summary
  • 28. Please fill the questionnaire ! You have a chance to win: Sponsored by: