SlideShare a Scribd company logo
Real life unit testingDror Helper
Who am I?Software DeveloperPart time blogger http://blog.drorhelper.com/@dhelperOne thing was the same wherever I worked…
AgendaUnit tests - what, how and whyTools of the tradeHow to write better testsWriting tests when it’s hard to test
Sounds familiar?Every ten bugs I fix I create a new one…I have no idea what caused that issue…I’d rather not change that function…It is impossible to unit test our project!Setting my test environment takes too long
Avoid stupid bugs
Unit testsUnit TestsTest specific functionalityClear pass/fail criteriaGood unit test runs in isolation
What is a Unit TestUnit tests[TestMethod]public void CheckPassword_ValidUser_ReturnTrue(){bool result = CheckPassword(“user”, “pass”);Assert.IsTrue(result);}
What is a Unit TestUnit tests[Test]public void CheckPassword_ValidUser_ReturnTrue(){bool result = CheckPassword(“user”, “pass”);Assert.That(result, Is.True);}
The kind of testUnit tests should be:SmallAtomicTest a single functional unitIsolated!Integration tests are used to test system wide functionalityUnit tests
Why use automated unit tests?Quick feedbackRegressionGain control of your codeUnit tests
Avoid stupid bugsUnit tests
Tools of the tradeToolsServerSource ControlBuild ServerBuild ScriptDev MachineTest RunnerUnit Testing FrameworkIsolation FrameworkCode Coverage
Continuous IntegrationToolsWhat’s new?CommitBuild Server(TeamCity)There you goStart workingBuild artifactsWe automatically gotError reports & logs
New version installer
Help files
More…Source Control(SVN)Build Agents(FinalBuilder)
Build Script at a GlanceTools
TeamCity at a GlanceTools
Development environmentMake it easy to write and run testsUnit test frameworkTest RunnerIsolation frameworkKnow where you standCode coverage Tools
Unit testing frameworksNUnitxUnitMSTestGallio (MbUnit)NBehaveList of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworksTools
Test RunnersToolsVisual Studio (MSTest)
TestDrive.Net
R# TestRunner
CodeRushTestRunner
NUnitItHow to write better testsWrite better testsWrite easy to understand testsReuse code where appropriateRunning test should be easyAvoid fragile testsTrust Your Tests!
Readability is importantWhy did the test fail?Avoid unnecessary debuggingUnderstand what the test does!Write better tests
Easy to understand unit testsNames are importantDon’t be afraid to repeat yourselfArrange-Act-AssertOr Act-Assert-ArrangeWrite better tests
Write readable testsTest only one thing (most of the time)KISS – avoid logic in your testWrite better tests
Duplicate code problemWrite better testsAfter refactoring I need to re-write my tests.Writing the same code twice is wrong
Reuse codeCreate objects using factoriesManipulate and configure initial stateRun common tests in common methods Write better tests
Just remember	Readability is important - It’s still ok to repeat yourselfWrite better tests
Easy to run	Running the tests takes too longSetting complicated testing environmentWrite better tests

More Related Content

PPTX
Advanced unit testing – real life examples and mistakes
PDF
Test Driven Development
ODP
Mistakes I have made
PPTX
Test Driven Development
PPTX
Test case writing
PPTX
Type mock isolator
PPTX
Mixing testing types to improve your testing results
PPTX
Unit testing
Advanced unit testing – real life examples and mistakes
Test Driven Development
Mistakes I have made
Test Driven Development
Test case writing
Type mock isolator
Mixing testing types to improve your testing results
Unit testing

What's hot (20)

PPTX
So you think you can write a test case
PPTX
Test Automation Architecture That Works by Bhupesh Dahal
PPTX
How to write defect
PPTX
xUnit test patterns 0
PPTX
An Overview of automated testing (1)
PPTX
An Introduction to Unit Testing
PPTX
Unit testing
PPTX
Automated tests
PPTX
Clean code
PDF
Tdd red-green-refactor
PDF
Sqa, test scenarios and test cases
PDF
Unit testing (workshop)
PDF
Php tests tips
PPTX
Mock driven development using .NET
PDF
Effective Unit Testing
PPTX
Moq presentation
PPTX
Roy Osherove TDD From Scratch
PPS
Test Cases Maintaining & Documenting
PPTX
An Introduction to unit testing
PDF
Unit testing in PHP
So you think you can write a test case
Test Automation Architecture That Works by Bhupesh Dahal
How to write defect
xUnit test patterns 0
An Overview of automated testing (1)
An Introduction to Unit Testing
Unit testing
Automated tests
Clean code
Tdd red-green-refactor
Sqa, test scenarios and test cases
Unit testing (workshop)
Php tests tips
Mock driven development using .NET
Effective Unit Testing
Moq presentation
Roy Osherove TDD From Scratch
Test Cases Maintaining & Documenting
An Introduction to unit testing
Unit testing in PHP
Ad

Viewers also liked (6)

PPTX
Unit 2 unit testing
PPTX
Test driven development in .Net - 2010 + Eclipse
PDF
Unit testing, principles
PDF
Workbook answer key unit 1
PDF
American english-file-2-workbook-answers
PDF
El112 new headway-plus_upper_intermediate_workbook_answer_key
Unit 2 unit testing
Test driven development in .Net - 2010 + Eclipse
Unit testing, principles
Workbook answer key unit 1
American english-file-2-workbook-answers
El112 new headway-plus_upper_intermediate_workbook_answer_key
Ad

Similar to Real Life Unit Testing (20)

PPTX
Unit tests & TDD
PDF
An Introduction to Unit Test Using NUnit
PPT
Automated testing overview
PPTX
Skillwise Unit Testing
PPTX
Building unit tests correctly with visual studio 2013
PDF
Unit Testing in Software Development: Why It Matters and How to Do It Right
PDF
Automated Testing on iOS
PPTX
Unit Testing and TDD 2017
PPTX
Unit testing
PDF
The Art of Unit Testing Feedback
PDF
Unit testing (Exploring the other side as a tester)
PDF
What Is Unit Testing_ A Complete Guide With Examples.pdf
PDF
Unit testing - An introduction
PPTX
Test driven development
PDF
What Is Unit Testing A Complete Guide With Examples.pdf
PDF
Agile Testing - What is it?
PDF
PPT
Automated Unit Testing and TDD
PPTX
Building unit tests correctly
PDF
Introduction To UnitTesting & JUnit
Unit tests & TDD
An Introduction to Unit Test Using NUnit
Automated testing overview
Skillwise Unit Testing
Building unit tests correctly with visual studio 2013
Unit Testing in Software Development: Why It Matters and How to Do It Right
Automated Testing on iOS
Unit Testing and TDD 2017
Unit testing
The Art of Unit Testing Feedback
Unit testing (Exploring the other side as a tester)
What Is Unit Testing_ A Complete Guide With Examples.pdf
Unit testing - An introduction
Test driven development
What Is Unit Testing A Complete Guide With Examples.pdf
Agile Testing - What is it?
Automated Unit Testing and TDD
Building unit tests correctly
Introduction To UnitTesting & JUnit

More from Dror Helper (20)

PPTX
Unit testing patterns for concurrent code
PPTX
The secret unit testing tools no one ever told you about
PPTX
Debugging with visual studio beyond 'F5'
PPTX
From clever code to better code
PPTX
From clever code to better code
PPTX
A software developer guide to working with aws
PPTX
The secret unit testing tools no one has ever told you about
PPTX
The role of the architect in agile
PDF
Harnessing the power of aws using dot net core
PPTX
Developing multi-platform microservices using .NET core
PPTX
Harnessing the power of aws using dot net
PPTX
Secret unit testing tools no one ever told you about
PPTX
C++ Unit testing - the good, the bad & the ugly
PPTX
Working with c++ legacy code
PPTX
Visual Studio tricks every dot net developer should know
PPTX
Secret unit testing tools
PPTX
Electronics 101 for software developers
PPTX
Navigating the xDD Alphabet Soup
PPTX
Who’s afraid of WinDbg
PPTX
Unit testing patterns for concurrent code
Unit testing patterns for concurrent code
The secret unit testing tools no one ever told you about
Debugging with visual studio beyond 'F5'
From clever code to better code
From clever code to better code
A software developer guide to working with aws
The secret unit testing tools no one has ever told you about
The role of the architect in agile
Harnessing the power of aws using dot net core
Developing multi-platform microservices using .NET core
Harnessing the power of aws using dot net
Secret unit testing tools no one ever told you about
C++ Unit testing - the good, the bad & the ugly
Working with c++ legacy code
Visual Studio tricks every dot net developer should know
Secret unit testing tools
Electronics 101 for software developers
Navigating the xDD Alphabet Soup
Who’s afraid of WinDbg
Unit testing patterns for concurrent code

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
KodekX | Application Modernization Development
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
A Presentation on Artificial Intelligence
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
KodekX | Application Modernization Development
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
NewMind AI Monthly Chronicles - July 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
A Presentation on Artificial Intelligence
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Real Life Unit Testing

Editor's Notes

  • #5: Software project should not be a ticking bomb.
  • #7: AtomicRepeatableNo dependency between tests/test orderClear pass/fail criteria
  • #14: The backbone of TDD (and development)Show how CI & script runner run the test suite – perhaps publish results to web