SlideShare une entreprise Scribd logo
1  sur  46
Unit testing
Dror Helper
Senior consultant
Tuesday, Novemeber 19, 2013
“Traditional” development
Requirements

Design

Implementation

Verification

Maintenance
Integration surprises
Bugs are discovered too late
The cost of bugs
Where does it hurt?
100%

The pain is here!

This is too late…

9
8
7

60%

6
5

40%

4

3
20%

2
1

0%

0
Requirements

Coding

Integration

% of Defects Introduced

Testing

Cost to Fix a Defect

Support

Thousand $s

% defects created

80%

10
When writing unit tests
Quick feedback
Am I writing the code right?
Am I’m writing the right thing?
Dependency & API analysis

Avoid stupid bugs
After writing a unit test
Immune to regression
Change your code without fear
Enable Rapid changes
In code documentation
What is a unit test?
Test specific functionality
Clear pass/fail criteria
Good unit test runs in isolation
This is a unit test
[TestMethod]
public void CheckPassword_ValidUser_ReturnTrue()
{
bool result = CheckPassword(“user”, “pass”);
Assert.IsTrue(result);
}
This is also a unit test
[Test]
public void CheckPassword_ValidUser_ReturnTrue()
{
bool result = CheckPassword(“user”, “pass”);
Assert.That(result, Is.True);
}
Unit tests are written by developers
Arrange Act Assert
Divide the unit test into three parts:
[Test]
public void test() throws Exception
{
// Arrange
int first = 1;
int second = 2;
Calculator calc = new Calculator();
// Act
int result = calc.Add(first, Second);
// Assert
Assert.AreEquals(3, result);
}
Project structure
It is crucial to have a consistent naming convention:
For Project:
<project under test>Tests
or
<project under test>.UnitTests
<project under test>.IntegrationTests
For files (Test case):
<class under test>Tests
Example: CalculatorTests

Never have your test in the same project as your production code!
Test naming
Test names should be descriptive and explicit.
Test names should express a specific requirement
I like to use:
Method_Scenario_Expected
a.k.a
UnitOfWork_StateUnderTest_ExpectedBehavior
Public void Sum_NegativeNumberAs1stParam_ExceptionThrown()
Public void Sum_simpleValues_Calculated ()
Public void Parse_SingleToken_ReturnsEqualTokenValue ()
From: http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html
Test classification
Unit tests should be:
– Small
– Atomic
– Test a single functional unit
– Isolated!

Integration tests are used to test system wide functionality
The test pyramid
Manual
testing
UI automation
Integration tests
Unit tests
The test pyramid
Manual
testing
UI automation
End to End flow tests
Scenario tests
Integration tests
Unit tests
Unit testing tools
Tools of the trade
Server
Build Server

Source Control

Build Script

Dev Machine
Unit Testing
Framework

Code
Coverage

Test Runner

Isolation
Framework
Continuous Integration Server
Build
What’s new?

Commit
There you go
Source Control
We automatically got
•Error reports & logs
•New version installer
•Help files
•More…

Build Agents
Team Foundation Server (TFS)
TeamCity
Development environment
• Make it easy to write and run tests
– Unit test framework
– Test Runner
– Isolation framework

• Know where you stand
– Code coverage
Unit test framework
Simplify the process of unit testing
Provide the following:

Control flow (attributes)
Signal success/failure (Assertions)

http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
Assertions
Throw exception when condition is false.
Easy to find:
Assert.X
StringAssert.X
CollectionAssert.X
New Syntax (Nunit):
Assert.That(x, Is.Equal(y));
Attributes
Declare information about the test:
• TestClass/TestFixture
• TestMethod/Test
• ExpectedException
• Ignore

• And more
Test Runners
Visual Studio
 TestDrive.Net
 R# TestRunner
 CodeRush TestRunner

Code coverage
Test Driven Development
a software development process that relies on the
repetition of a very short development cycle
Test Driven Development
Red

Refactor

Green
The complete flow
Write
new Test
Run all
tests

Run Test
(fail)

Refactor

Write
code
Run test
(pass)
Unit tests != TDD
• The purpose of a unit test is to test a unit of code in isolation
• TDD is used to drive the design of an application.
• used to express what application code should do before the
application code is actually written.
Examples, demonstrations & fun

A DAY IN THE LIFE OF A TDD'ER
A Day in the Life of a TDD'er
• The tools we use
• Writing some code
• OK, who broke the Build?!

• Too much spare time…
The Tools We Use(d)
•
•
•
•
•
•

Unit testing – MSTest/NUnit
Build automation – FinalBuilder
Continuous Integration – TeamCity
Integrated tools – R#, TestDriven.NET
Isolation Framework – Isolator (surprise!)
Build Bunny!
Writing Some Code


We begin with a clean slate
Write
new
test
Run
tests

Refactor

Run All
tests

Write
code
Writing Some Code


An exercise in futility…
Write
new
test
Run
tests

Refactor

Run all
tests

Write
code
Writing Some Code


Now we get our hands dirty
Write
new
Test
Run
tests

Refactor

Run all
tests

Write
code
Writing Some Code


Make sure everything’s fine…
Write
new
Test
Run
tests

Refactor

Run all
tests

Write
code
Writing Some Code


… and make it perform/look better
Write
new
test
Run
tests

Refactor

Run all
tests

Write
code
Writing Some Code


Lets take her out for another spin…
Write
new
Test
Run
tests

Refactor

Run all
tests

Write
code
Want to learn more
Check out the bowling kata:
http://www.objectmentor.com/resources/articles/xpepisode.htm
More TDD problems:
https://sites.google.com/site/tddproblems/all-problems-1
OK, Who Broke the Build?
• Something went horribly wrong!
– And it’s easy to find who to blame 
– But it’s easy to find out what happened

• Why is this important?
– The project heartbeat
– Healthy build == easy to release
Too Much Spare Time
The foosball table
The build bunny
The Shooting of The Zombies
Helping children with computer skills

•
•
•
•
The unit tester bookshelf
Presenter contact details
C: 972.50.7668543
e: drorh@codevalue.net
b: blog.drorhelper.com
w: www.codevalue.net

Contenu connexe

Tendances

Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnitkleinron
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testingAdam Stephensen
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBaskar K
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentJohn Blum
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkHumberto Marchezi
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with AgileKen McCorkell
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test PresentationSayedur Rahman
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Thomas Weller
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytestSuraj Deshmukh
 
Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated TestingLee Englestone
 

Tendances (20)

Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with Agile
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Unit testing
Unit testingUnit testing
Unit testing
 
Google test training
Google test trainingGoogle test training
Google test training
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 

Similaire à Unit tests & TDD

Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingCameron Presley
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis Engineering Software Lab
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Comunidade NetPonto
 
Do you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well plannedDo you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well plannedJosé San Román A. de Lara
 
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
 
Slides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testingSlides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testingSwapnilNarayan
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitweili_at_slideshare
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Jacinto Limjap
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and AutomationMahesh Salaria
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Yves Hoppe
 

Similaire à Unit tests & TDD (20)

Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
AAA Automated Testing
AAA Automated TestingAAA Automated Testing
AAA Automated Testing
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
Do you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well plannedDo you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well planned
 
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
 
Slides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testingSlides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testing
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
 

Plus de Dror Helper

Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
 
The secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you aboutThe secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you aboutDror Helper
 
Debugging with visual studio beyond 'F5'
Debugging with visual studio beyond 'F5'Debugging with visual studio beyond 'F5'
Debugging with visual studio beyond 'F5'Dror Helper
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better codeDror Helper
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better codeDror Helper
 
A software developer guide to working with aws
A software developer guide to working with awsA software developer guide to working with aws
A software developer guide to working with awsDror Helper
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutDror Helper
 
The role of the architect in agile
The role of the architect in agileThe role of the architect in agile
The role of the architect in agileDror Helper
 
Harnessing the power of aws using dot net core
Harnessing the power of aws using dot net coreHarnessing the power of aws using dot net core
Harnessing the power of aws using dot net coreDror Helper
 
Developing multi-platform microservices using .NET core
 Developing multi-platform microservices using .NET core Developing multi-platform microservices using .NET core
Developing multi-platform microservices using .NET coreDror Helper
 
Harnessing the power of aws using dot net
Harnessing the power of aws using dot netHarnessing the power of aws using dot net
Harnessing the power of aws using dot netDror Helper
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutDror Helper
 
C++ Unit testing - the good, the bad & the ugly
C++ Unit testing - the good, the bad & the uglyC++ Unit testing - the good, the bad & the ugly
C++ Unit testing - the good, the bad & the uglyDror Helper
 
Working with c++ legacy code
Working with c++ legacy codeWorking with c++ legacy code
Working with c++ legacy codeDror Helper
 
Visual Studio tricks every dot net developer should know
Visual Studio tricks every dot net developer should knowVisual Studio tricks every dot net developer should know
Visual Studio tricks every dot net developer should knowDror Helper
 
Secret unit testing tools
Secret unit testing toolsSecret unit testing tools
Secret unit testing toolsDror Helper
 
Electronics 101 for software developers
Electronics 101 for software developersElectronics 101 for software developers
Electronics 101 for software developersDror Helper
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupDror Helper
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
 
Who’s afraid of WinDbg
Who’s afraid of WinDbgWho’s afraid of WinDbg
Who’s afraid of WinDbgDror Helper
 

Plus de Dror Helper (20)

Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
 
The secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you aboutThe secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you about
 
Debugging with visual studio beyond 'F5'
Debugging with visual studio beyond 'F5'Debugging with visual studio beyond 'F5'
Debugging with visual studio beyond 'F5'
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
 
From clever code to better code
From clever code to better codeFrom clever code to better code
From clever code to better code
 
A software developer guide to working with aws
A software developer guide to working with awsA software developer guide to working with aws
A software developer guide to working with aws
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you about
 
The role of the architect in agile
The role of the architect in agileThe role of the architect in agile
The role of the architect in agile
 
Harnessing the power of aws using dot net core
Harnessing the power of aws using dot net coreHarnessing the power of aws using dot net core
Harnessing the power of aws using dot net core
 
Developing multi-platform microservices using .NET core
 Developing multi-platform microservices using .NET core Developing multi-platform microservices using .NET core
Developing multi-platform microservices using .NET core
 
Harnessing the power of aws using dot net
Harnessing the power of aws using dot netHarnessing the power of aws using dot net
Harnessing the power of aws using dot net
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you about
 
C++ Unit testing - the good, the bad & the ugly
C++ Unit testing - the good, the bad & the uglyC++ Unit testing - the good, the bad & the ugly
C++ Unit testing - the good, the bad & the ugly
 
Working with c++ legacy code
Working with c++ legacy codeWorking with c++ legacy code
Working with c++ legacy code
 
Visual Studio tricks every dot net developer should know
Visual Studio tricks every dot net developer should knowVisual Studio tricks every dot net developer should know
Visual Studio tricks every dot net developer should know
 
Secret unit testing tools
Secret unit testing toolsSecret unit testing tools
Secret unit testing tools
 
Electronics 101 for software developers
Electronics 101 for software developersElectronics 101 for software developers
Electronics 101 for software developers
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Who’s afraid of WinDbg
Who’s afraid of WinDbgWho’s afraid of WinDbg
Who’s afraid of WinDbg
 

Dernier

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Dernier (20)

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Unit tests & TDD

  • 1. Unit testing Dror Helper Senior consultant Tuesday, Novemeber 19, 2013
  • 5. The cost of bugs Where does it hurt? 100% The pain is here! This is too late… 9 8 7 60% 6 5 40% 4 3 20% 2 1 0% 0 Requirements Coding Integration % of Defects Introduced Testing Cost to Fix a Defect Support Thousand $s % defects created 80% 10
  • 6. When writing unit tests Quick feedback Am I writing the code right? Am I’m writing the right thing? Dependency & API analysis Avoid stupid bugs
  • 7. After writing a unit test Immune to regression Change your code without fear Enable Rapid changes In code documentation
  • 8. What is a unit test? Test specific functionality Clear pass/fail criteria Good unit test runs in isolation
  • 9. This is a unit test [TestMethod] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.IsTrue(result); }
  • 10. This is also a unit test [Test] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.That(result, Is.True); }
  • 11. Unit tests are written by developers
  • 12. Arrange Act Assert Divide the unit test into three parts: [Test] public void test() throws Exception { // Arrange int first = 1; int second = 2; Calculator calc = new Calculator(); // Act int result = calc.Add(first, Second); // Assert Assert.AreEquals(3, result); }
  • 13. Project structure It is crucial to have a consistent naming convention: For Project: <project under test>Tests or <project under test>.UnitTests <project under test>.IntegrationTests For files (Test case): <class under test>Tests Example: CalculatorTests Never have your test in the same project as your production code!
  • 14. Test naming Test names should be descriptive and explicit. Test names should express a specific requirement I like to use: Method_Scenario_Expected a.k.a UnitOfWork_StateUnderTest_ExpectedBehavior Public void Sum_NegativeNumberAs1stParam_ExceptionThrown() Public void Sum_simpleValues_Calculated () Public void Parse_SingleToken_ReturnsEqualTokenValue () From: http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html
  • 15. Test classification Unit tests should be: – Small – Atomic – Test a single functional unit – Isolated! Integration tests are used to test system wide functionality
  • 16. The test pyramid Manual testing UI automation Integration tests Unit tests
  • 17. The test pyramid Manual testing UI automation End to End flow tests Scenario tests Integration tests Unit tests
  • 19. Tools of the trade Server Build Server Source Control Build Script Dev Machine Unit Testing Framework Code Coverage Test Runner Isolation Framework
  • 20. Continuous Integration Server Build What’s new? Commit There you go Source Control We automatically got •Error reports & logs •New version installer •Help files •More… Build Agents
  • 23. Development environment • Make it easy to write and run tests – Unit test framework – Test Runner – Isolation framework • Know where you stand – Code coverage
  • 24. Unit test framework Simplify the process of unit testing Provide the following: Control flow (attributes) Signal success/failure (Assertions) http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
  • 25. Assertions Throw exception when condition is false. Easy to find: Assert.X StringAssert.X CollectionAssert.X New Syntax (Nunit): Assert.That(x, Is.Equal(y));
  • 26. Attributes Declare information about the test: • TestClass/TestFixture • TestMethod/Test • ExpectedException • Ignore • And more
  • 27. Test Runners Visual Studio  TestDrive.Net  R# TestRunner  CodeRush TestRunner 
  • 29. Test Driven Development a software development process that relies on the repetition of a very short development cycle
  • 31. The complete flow Write new Test Run all tests Run Test (fail) Refactor Write code Run test (pass)
  • 32. Unit tests != TDD • The purpose of a unit test is to test a unit of code in isolation • TDD is used to drive the design of an application. • used to express what application code should do before the application code is actually written.
  • 33. Examples, demonstrations & fun A DAY IN THE LIFE OF A TDD'ER
  • 34. A Day in the Life of a TDD'er • The tools we use • Writing some code • OK, who broke the Build?! • Too much spare time…
  • 35. The Tools We Use(d) • • • • • • Unit testing – MSTest/NUnit Build automation – FinalBuilder Continuous Integration – TeamCity Integrated tools – R#, TestDriven.NET Isolation Framework – Isolator (surprise!) Build Bunny!
  • 36. Writing Some Code  We begin with a clean slate Write new test Run tests Refactor Run All tests Write code
  • 37. Writing Some Code  An exercise in futility… Write new test Run tests Refactor Run all tests Write code
  • 38. Writing Some Code  Now we get our hands dirty Write new Test Run tests Refactor Run all tests Write code
  • 39. Writing Some Code  Make sure everything’s fine… Write new Test Run tests Refactor Run all tests Write code
  • 40. Writing Some Code  … and make it perform/look better Write new test Run tests Refactor Run all tests Write code
  • 41. Writing Some Code  Lets take her out for another spin… Write new Test Run tests Refactor Run all tests Write code
  • 42. Want to learn more Check out the bowling kata: http://www.objectmentor.com/resources/articles/xpepisode.htm More TDD problems: https://sites.google.com/site/tddproblems/all-problems-1
  • 43. OK, Who Broke the Build? • Something went horribly wrong! – And it’s easy to find who to blame  – But it’s easy to find out what happened • Why is this important? – The project heartbeat – Healthy build == easy to release
  • 44. Too Much Spare Time The foosball table The build bunny The Shooting of The Zombies Helping children with computer skills • • • •
  • 45. The unit tester bookshelf
  • 46. Presenter contact details C: 972.50.7668543 e: drorh@codevalue.net b: blog.drorhelper.com w: www.codevalue.net

Notes de l'éditeur

  1. Example: writing unit tests
  2. Ask them – why is the test name so important?
  3. Succeeding with Agile. Cohn, Mike
  4. Succeeding with Agile. Cohn, Mike
  5. The backbone of TDD (and development)Show how CI &amp; script runner run the test suite – perhaps publish results to web
  6. Should show:NUnit
  7. Resharper