SlideShare a Scribd company logo
Sachin Kainth
Unit Testing
Contents
• General discussion on unit testing
• Unit testing tools
• Test Driven Development
• Conclude
What is Unit Testing
• Software design and development method that
gives developer confidence that individual units
of code are fit for purpose
The Importance of Unit Testing
• Forced to keep code simple and testable
• Units tend to do only one thing
• Code is more maintainable
• Can take the place of formal design
• Code is less buggy
• Code is more robust
The Importance of Unit Testing
• Provides executable documentation
• Natural set of regression tests
• Makes refactoring safer
• Less (severe) bugs founds further down the cycle
The Importance of Unit Testing
Ariane 5 Flight 501 (1996)
• Launch system developed under the authority of
the European Space Agency
• The navigation package was inherited from the
Ariane 4 without proper testing
• Veered off course and exploded soon after take
off
• Cost of failure was more than US$370 million
Why Unit Testing is not always done
• Developer
• Considered tedious and uninteresting
• “My code doesn’t need testing”
• Gray box testing done instead
• Unfamiliarity with unit testing tools and techniques
• Test development is a combinatorial problem
• More lines of test code needed than production code
• Developers test as they code
• Tests are a maintenance overhead
• Who will test the unit tests
• Not all software projects are “complex”
• Maintaining a system which has no unit tests
Why Unit Testing is not always done
• Client
• Not a deliverable
• No time, budget
• As clients do not always know what they want, tests
may need to be thrown away
Why Unit Testing is not always done
• Management
• Doesn’t add anything to the project
Unit Testing Tools
• NUnit
• Microsoft
• TestDriven.NET add-in
NUnit Attributes
• [TestFixture]
• [Test]
• [TestFixtureSetUp]
• [TestFixtureTearDown]
• [Setup]
• [TearDown]
• [ExpectedException]
Demo
A simple demo of NUnit
Demo
A simple demo of Visual Studio test projects
Demo
A simple demo of TestDriven.NET
Demo
Testing without a framework
Test Driven Development Technique
Add test(s) before implementing feature
Run all tests and see if new test(s) fail
Write code to pass new test(s)
Run all tests and see if all pass
Refactor code and rerun all tests
Test Driven Development Technique
Benefits:
• Makes developer focus on behaviour and
requirements early on
• 100% test coverage
• Extensive refactoring made possible
Demo
An example of Test Driven Development
Summary
• Unit testing is a Good Thing
• Tools
• TDD
References
• http://en.wikipedia.org/wiki/Test-
driven_development
• http://www.nunit.org/index.php
• http://en.wikipedia.org/wiki/V-
Model_(software_development)
• http://www.wired.com/software/coolapps/news/20
05/11/69355
• http://en.wikipedia.org/wiki/List_of_notable_softw
are_bugs
• http://www.coleyconsulting.co.uk/testtype.htm
• http://www.youtube.com/watch?v=REDO7eYwGTU
Questions
?

More Related Content

PDF
Continuous Integration
Stanislav Tiurikov
 
PPT
Test automation in agile ecosystem
JohnRizer
 
ZIP
Introduction To Continuous Integration
Christopher Read
 
PDF
CNUG TDD June 2014
Mayank Srivastava
 
PPT
Demo1ghjkl
crazyvirtue
 
PPTX
Addressing Security Regression Through Unit Testing
Christopher Grayson
 
PDF
Continuous integration practices to improve the software quality
Fabricio Epaminondas
 
PPTX
Continuous Delivery Presentation
Mauricio Ferreyra
 
Continuous Integration
Stanislav Tiurikov
 
Test automation in agile ecosystem
JohnRizer
 
Introduction To Continuous Integration
Christopher Read
 
CNUG TDD June 2014
Mayank Srivastava
 
Demo1ghjkl
crazyvirtue
 
Addressing Security Regression Through Unit Testing
Christopher Grayson
 
Continuous integration practices to improve the software quality
Fabricio Epaminondas
 
Continuous Delivery Presentation
Mauricio Ferreyra
 

What's hot (20)

PDF
Vladimir Lozanov How to deliver high quality apps to the app store
Аліна Шепшелей
 
PPTX
Android tdd
Nhan Cao
 
PDF
Test Automation
nikos batsios
 
PDF
Continuous Integration
drluckyspin
 
PPTX
Test Driven Development
Sergey Aganezov
 
PDF
Introduction to Automated Testing
Lars Thorup
 
PPT
System Integration & Build Management
Computing Cage
 
PPTX
Using Continuous Integration To Ensure Project Health New
bartlowe
 
PPTX
Software engineering
bartlowe
 
PDF
Quickstart for continuous integration
Fabricio Epaminondas
 
PPTX
DevQAOps - Surviving in a DevOps World
Winston Laoh
 
PDF
Jenkins Test Automation with codeBeamer ALM
Intland Software GmbH
 
PPTX
Agile Engineering Sparker GLASScon 2015
Stephen Ritchie
 
PDF
Continuous Integration 101
John Ferguson Smart Limited
 
PPTX
Lets talk about CI CD Pipeline in Agile
Poonam Panday
 
PPTX
Keeping Your CI/CD Pipeline as Fast as It Needs to Be
Abraham Marin-Perez
 
PDF
Info Card - Techical Debt Management
Fabricio Epaminondas
 
PPTX
How To Transform the Manual Testing Process to Incorporate Test Automation
Ranorex
 
PDF
Continuous Integration at T3CON08
Sebastian Kurfürst
 
Vladimir Lozanov How to deliver high quality apps to the app store
Аліна Шепшелей
 
Android tdd
Nhan Cao
 
Test Automation
nikos batsios
 
Continuous Integration
drluckyspin
 
Test Driven Development
Sergey Aganezov
 
Introduction to Automated Testing
Lars Thorup
 
System Integration & Build Management
Computing Cage
 
Using Continuous Integration To Ensure Project Health New
bartlowe
 
Software engineering
bartlowe
 
Quickstart for continuous integration
Fabricio Epaminondas
 
DevQAOps - Surviving in a DevOps World
Winston Laoh
 
Jenkins Test Automation with codeBeamer ALM
Intland Software GmbH
 
Agile Engineering Sparker GLASScon 2015
Stephen Ritchie
 
Continuous Integration 101
John Ferguson Smart Limited
 
Lets talk about CI CD Pipeline in Agile
Poonam Panday
 
Keeping Your CI/CD Pipeline as Fast as It Needs to Be
Abraham Marin-Perez
 
Info Card - Techical Debt Management
Fabricio Epaminondas
 
How To Transform the Manual Testing Process to Incorporate Test Automation
Ranorex
 
Continuous Integration at T3CON08
Sebastian Kurfürst
 
Ad

Viewers also liked (13)

PDF
MPI_PQ_2015_ISSUE5 @ 2014 New Property Guidelines affected Foreign Purchases.3-7
Siti Nur Adilena Amran
 
PDF
ARC I Certificate
mohan singh
 
PPTX
Rationallogistics. Ключевые инструменты снижения себестоимости логистики
Rational Logistics
 
PDF
A tragedy with a happy ending? The United States before the Paris Climate Summit
Worldwatch Institute
 
PDF
First Aid Certificate
Kundai Dennis Musuka
 
PDF
Bodegaspymesespaolasexportadoras 110831114733-phpapp02
Alejandro Rodríguez
 
PPTX
PowerHouse Online Induction and Training Portal
smoothit
 
PDF
Duck&Whale Rennsport Review V2
Lee Dean
 
PPT
Hobbbes thomas trabajo de filosofia
Brandon Fountain Roja
 
DOCX
Screen play format
DG160859
 
DOCX
Project report on marketing mix mapping for haier in refrigerators, washing m...
Projects Kart
 
PDF
XPRIZE Brand Book
Trish Halamandaris
 
MPI_PQ_2015_ISSUE5 @ 2014 New Property Guidelines affected Foreign Purchases.3-7
Siti Nur Adilena Amran
 
ARC I Certificate
mohan singh
 
Rationallogistics. Ключевые инструменты снижения себестоимости логистики
Rational Logistics
 
A tragedy with a happy ending? The United States before the Paris Climate Summit
Worldwatch Institute
 
First Aid Certificate
Kundai Dennis Musuka
 
Bodegaspymesespaolasexportadoras 110831114733-phpapp02
Alejandro Rodríguez
 
PowerHouse Online Induction and Training Portal
smoothit
 
Duck&Whale Rennsport Review V2
Lee Dean
 
Hobbbes thomas trabajo de filosofia
Brandon Fountain Roja
 
Screen play format
DG160859
 
Project report on marketing mix mapping for haier in refrigerators, washing m...
Projects Kart
 
XPRIZE Brand Book
Trish Halamandaris
 
Ad

Similar to Testing (20)

PPTX
An Introduction to Unit Testing
Sahar Nofal
 
PDF
Tdd
Dmitry Savin
 
PPTX
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Codecamp Romania
 
PPT
Unit testing
dubbu
 
PPT
Tech talks #1- Unit testing and TDD
DUONG Trong Tan
 
PPTX
Test-Driven-Development.pptx
dheeraj438799
 
PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
PPTX
Unit Testing and TDD 2017
Xavi Hidalgo
 
PPT
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
PDF
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
Hendrik Neumann
 
PDF
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat
 
PDF
50120140502011
IAEME Publication
 
PDF
50120140502011
IAEME Publication
 
PPTX
Test driven development(tdd)
Omar Youssef Shiha
 
PDF
TDD Workshop UTN 2012
Facundo Farias
 
PPTX
The Test way
Mikhail Grinfeld
 
PPT
Test_Driven_Development_v5.ppt
dheeraj438799
 
PPTX
Test driven development
Luis Goldster
 
PPTX
Test driven development
Young Alista
 
PPTX
Test driven development
Tony Nguyen
 
An Introduction to Unit Testing
Sahar Nofal
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Codecamp Romania
 
Unit testing
dubbu
 
Tech talks #1- Unit testing and TDD
DUONG Trong Tan
 
Test-Driven-Development.pptx
dheeraj438799
 
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Unit Testing and TDD 2017
Xavi Hidalgo
 
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
Hendrik Neumann
 
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat
 
50120140502011
IAEME Publication
 
50120140502011
IAEME Publication
 
Test driven development(tdd)
Omar Youssef Shiha
 
TDD Workshop UTN 2012
Facundo Farias
 
The Test way
Mikhail Grinfeld
 
Test_Driven_Development_v5.ppt
dheeraj438799
 
Test driven development
Luis Goldster
 
Test driven development
Young Alista
 
Test driven development
Tony Nguyen
 

Testing

  • 2. Contents • General discussion on unit testing • Unit testing tools • Test Driven Development • Conclude
  • 3. What is Unit Testing • Software design and development method that gives developer confidence that individual units of code are fit for purpose
  • 4. The Importance of Unit Testing • Forced to keep code simple and testable • Units tend to do only one thing • Code is more maintainable • Can take the place of formal design • Code is less buggy • Code is more robust
  • 5. The Importance of Unit Testing • Provides executable documentation • Natural set of regression tests • Makes refactoring safer • Less (severe) bugs founds further down the cycle
  • 6. The Importance of Unit Testing Ariane 5 Flight 501 (1996) • Launch system developed under the authority of the European Space Agency • The navigation package was inherited from the Ariane 4 without proper testing • Veered off course and exploded soon after take off • Cost of failure was more than US$370 million
  • 7. Why Unit Testing is not always done • Developer • Considered tedious and uninteresting • “My code doesn’t need testing” • Gray box testing done instead • Unfamiliarity with unit testing tools and techniques • Test development is a combinatorial problem • More lines of test code needed than production code • Developers test as they code • Tests are a maintenance overhead • Who will test the unit tests • Not all software projects are “complex” • Maintaining a system which has no unit tests
  • 8. Why Unit Testing is not always done • Client • Not a deliverable • No time, budget • As clients do not always know what they want, tests may need to be thrown away
  • 9. Why Unit Testing is not always done • Management • Doesn’t add anything to the project
  • 10. Unit Testing Tools • NUnit • Microsoft • TestDriven.NET add-in
  • 11. NUnit Attributes • [TestFixture] • [Test] • [TestFixtureSetUp] • [TestFixtureTearDown] • [Setup] • [TearDown] • [ExpectedException]
  • 12. Demo A simple demo of NUnit
  • 13. Demo A simple demo of Visual Studio test projects
  • 14. Demo A simple demo of TestDriven.NET
  • 16. Test Driven Development Technique Add test(s) before implementing feature Run all tests and see if new test(s) fail Write code to pass new test(s) Run all tests and see if all pass Refactor code and rerun all tests
  • 17. Test Driven Development Technique Benefits: • Makes developer focus on behaviour and requirements early on • 100% test coverage • Extensive refactoring made possible
  • 18. Demo An example of Test Driven Development
  • 19. Summary • Unit testing is a Good Thing • Tools • TDD
  • 20. References • http://en.wikipedia.org/wiki/Test- driven_development • http://www.nunit.org/index.php • http://en.wikipedia.org/wiki/V- Model_(software_development) • http://www.wired.com/software/coolapps/news/20 05/11/69355 • http://en.wikipedia.org/wiki/List_of_notable_softw are_bugs • http://www.coleyconsulting.co.uk/testtype.htm • http://www.youtube.com/watch?v=REDO7eYwGTU

Editor's Notes

  • #4: Business Case: What benefits new system or change will deliver to the business and outlines costs Requirements: Define what the system will achieve to meet the need identified. Functional and Non-Functional. Functional: What the system should do. E.g. “should print invoices” Non-Functional: How a system is supposed to be. E.g. “should print them quickly”. They are the qualities of the system. Examples are accessibility, response time, usability System Specification: How the system shall achieve requirements by defining them in computer terms System Design: Detailed design document mapping features required onto components, defining relationships between these components Component Design: Tells you how each component performs its processing Shouldn’t really think of this as a linear process like Waterfall but can be iterative. Interface testing: communication of components.
  • #6: Executable documentation: unit tests tell you inappropriate/appropriate use of the unit as well as negative behaviours that are trapped by the unit Refactoring: changes to code that leave the original functionality unchanged but do change the design of the code sp that it is cleaner, more efficient and easier to test
  • #7: Ariane 5 flew faster, resulting in larger values of some variables in the navigation software.   Shortly after launch, an attempt to convert a 64-bit floating-point number into a 16-bit integer generated an overflow.  The error was caught, but the code that caught it elected to shut down the subsystem 
  • #8: Gray Box Testing - Test designed based on the knowledge of algorithm, internal states, architectures, or other high -level descriptions of the program behaviour.
  • #9: Combinatorial problem: if statement requires two tests at least More lines of test code: 3-5 lines for 1 line
  • #11: Open source unit testing framework for .NET - free .Net version of the XUnit family of tools
  • #12: Attributes can be used to document classes, specify runtime information, and even dictate runtime behaviour. NUnit Attributes [TestFixture] - Marks a class as containing tests and optionally setup or teardown methods. The class must be public (so that NUnit can call the methods in it) and not abstract. [Test] - Marks a method as a test method. The method must not have any parameters. [Setup] - Used to identify a method that contains code that gets executed before each test method is called. [TearDown] - Used to identify a method that contains code that gets executed after each test method is called. [TestFixtureSetUp] - Used to identify a method that contains code that gets executed before any of the test methods is called. [TestFixtureTearDown] - Used to identify a method that contains code that gets executed after all test methods have been called. [ExpectedException] - Specifies that the execution of a test is expected to throw an exception.
  • #16: Lucene DateTime only supports all AD ranges SQL dates 1753 or 1 AD Dotlucene only supports 1970 onwards
  • #17: The reason you write code to just pass the test as quick as possible is that you want to verify quickly that the new code does what you want it to And you will only write code that passes the test and not ‘allow for’ additional untested code Software development technique that uses short development iterations based on pre-written test cases that define desired improvements or new features Not just a testing methodology but a software design technique Key concept: write tests first Developers should make 1 to 10 edits per cycle to the code.
  • #18: Writing tests first enable developer to focus on just what is required Refactoring possible: because you have tests to help you check whether the changes are good or not Loosely coupled: components depend on each other to the least possible extent. Developer thinks about code as small unit that can be written and tested independently. This leads to smaller and more focused classes.
  • #19: 1 2 3 4 to 20 21 to 29 30 31 to 39 40 to 99 100 101 to 199 200 201 to 299 300 to 999 1000 1001 to 9999 10,000 to 999,999 1,000,000 to 999,999,999 1,000,000,000 to 2,147,483,647 0 -1 -2,147,483,648