• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Test Driven Development
 

Test Driven Development

on

  • 696 views

 

Statistics

Views

Total Views
696
Views on SlideShare
691
Embed Views
5

Actions

Likes
0
Downloads
38
Comments
0

2 Embeds 5

http://www.linkedin.com 4
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • About myself and company Tell the objective of the presentation: What is TDD, WHY TDD and HOWDefine the TDD, brief the history: TDD is the core part of Agile code development approach derived from Extreme Programming and the principles of Agile Manifesto. TDD is not all that new, an early reference to that use of TDD is that NASA project Mercury with 1960’sDespite its name, TDD is not a testing technique, but rather a development
  • I would considered usefulness of this presentation at the end, if it can create a curiosity about TDD among those who haven’t heard TDD or haven’t tried yet. And on those who know TDD and writes the test but only after writing production code. If they decide or at least give a try to make an habit of writing the test first. Production code here, I mean to say the functional code.
  • TDD is not new, but kinda new in agile methodology after kent beck introduced to his team who were following XP approach.In recent years, more focus has been on best practices and pattern rather then design principles or model. Today people talk about how to write clean code, how to write managable code, BDD all are best practices… This is a method of developing software that adopts a test-first approach.
  • TDD is a mindset , a mental modelBy writing the test first means you are asking yourself what needs to be done, Martin FowlerTesting first actually leads us to think deeply about design at design time.Writing test means what we're actually writing a (usually) partial behavioural contract against a component under test in a given context. So at beginning this is not a unit test that verifies the logical unit. Its just an behavioral contract
  • Failing test means not compile error but having some logical error miss match. You write you own test, don’t wait for others
  • Refactoring is when it is done design, I don’t claim I can guess the right design at first. So Design emerges with thoughts, care and small steps. Refactor
  • Steps you follow for TDD
  • When we say test in TDD, it often refers to unit testing, which is…Gives the test coverage.If you can write the perfect test, you got the flow of TDD.,Mock-up libraries available to make unit testing easier and independent.Learning TDD is difficult if you don’t know how to write effective tests.
  • Why do I care?Some developers try to avoid Test Driven Development because of all the extra time it takes to create the tests. We like to jump directly to the coding because we thinks we got it and go on writing code. If Lucky the code runs as we expected but most of the time it doesn’t because there is not anything that provides any cross check. So ends up with too much bugs. However, this time is made up for later on in the development phase.  In test-last development, when you complete the project you run tests, then go back and dig through your code looking for whatever has caused the test fail.  Often there are many separate items that work together to cause failure.  A developer can spend a long time looking back through the code.  With TDD however, once the entire program is completed you can be confident that the code works.  You have been testing it throughout the entire process.  Any time you encounter a problem during the development process, there are a multitude of tests already in operation that will allow you to quickly isolate the problem area.  Defects sometimes occur when changing one part of the code affects another part in an unexpected way.  By creating and constantly re-running low-level tests, these unexpected defects can be minimized.
  • A research paper shows that students who write tests first end up writing more code and being more productive and less development cost.
  • Bugs in injected accidentially when refactoring the code. We know programming often ends up passing such code to the QA team who finds such coding errors. You know QA is not for testing coding errors. They are for functional testing….
  • test should reflect the behavior of your code. Test becomes significant part of your technical documentation. You know Programmer don’t like reading the documentation written on paper. If the see any class or operations, they try to understand by looking the code that are invoking them. See this is what the test code exactly do. Helps to visualize requirements and what needs to be doneWhy write the test before the code is better? because it describe the behaviour of the code you are going to write. So its a specification. How would this be better then regular specification documented/written in the piece of paper? because it runs. it tell whether its right or wrong. it significantly reduce the minor progrmmer's bug. How likely a programmer passes the product to the QA group? QA is not to test codding errors but functional test. 
  • When you have to implement any requirement, first question, if the existing design is best that enables you to implement the functionality.Testability on TDD is just a side-effect of good design. All the production code already have running tests. Testability means not just unit testing, but integration testing, and functional testing….Helps on pair programming…QA’s life easy.So we get a double benefit from test-first approaches, not only do they lead us to think deeply about design at design time, but their legacy is a test suite that documents and supports ongoing development of the system.
  • It has been proven again and again that, those who writes the test first always ends writing lots of code and less debugging.It is necessary to understand and have correct mindset about TDD. Otherwise people struggle with TDD and TDD seems to cost more in maintenance then value it could have return. We should keep writing the tests until all of our functional requirements are covered by tests.Its not just a test, as xunit test or assert portraysAfter working TDD-style for a couple of years, people usually get better. BDD seems like a more natural approach for learning test-first development.I think one of the challenges for people starting out with TDD is that they first and foremost perceive TDD as a testing discipline. TDD is much more; it’s about how you handle your requirements and it is about application design. BDD, I think, helps in the sense that it more explicitly focuses on handling requirements.This all sounds simple in principle, but when you are first learning to take TDD approach it proves requires great discipline because it is easy to “slip” and write the functional code first writing a new test. One of the advantages pair programming is that your pair helps you to stay on track.

Test Driven Development Test Driven Development Presentation Transcript

  • TestDrivenDevelopment
    a coding practice
    Rupesh Bhochhibhoya
    Software Engineer,
    Telogical Systems
  • Intended Audiences
    • Those who are unaware of TDD or haven’t done TDD
    • Those who know what TDD means but haven’t got its flow
  • What is TDD ?
    One of the best software development practice/habit/technique used in Agile methodology that relies on the repetitive short development cycle.
    Each short development cycle is formed following 3 basic rules
  • Requirements
    Requirements
    Design
    TDD model
    Design
    Testing
    Implementation
    Implementation
    Testing
    waterfall model
    Deployment & Maintenance
    Deployment & Maintenance
  • Rule #1
    Write a test first that is just enough to fail before any production code that you are going to write. There should be only one reason for test to fail. So, each test is to specific one logical unit. The test case defines a desired functionality you want to see. This is also called Test-First approach.
  • Rule #2
    Write a production code that is just enough to pass the test. This make sure production code is doing exactly what test wanted. No any abnormal behavior.
  • Rule #3
    Refactor the production code to remove duplicationwithout changing the external behavior as desired by test units. We also refactor test code to make it more readable, remove duplication and add more logical unit test.
  • Refactor Production code
    Run test suite
    Fail
    How TDD ?
    Pass
    Add a test
    Run the complete test suite, ensure all pass.
    Add a new test code that is just enough to fail.
    Run the test and ensure it fails
    Then add production code just enough to make the test pass.
    Fourth step is to run the test again.
    If it fails, need to work again in production code and retest.
    Once test passes, the next step is to refactor any duplication out of your design as needed.
    SO: TDD = TFD + Refactoring…
    Pass
    Run the test
    Pass
    Fail
    Add/Modify Production code
    Fail
    Run the tests
  • Good Test Code in TDD…
    Describes the behavior of the code you are going to write.
    Run fast.
    Run in isolation.
    Should not be data driven.
    Should not communicates across the network.
    Should not interacts with file system
  • TDD Demo
    You write your own test
    You have a testing framework(Junit).
    Development environment must provide rapid response to small changes(CI)
    Eclipse IDE,
    Etc.
  • Why TDD
  • TDD reduces programmer’s bugs
    When you already have Tests that documents how your code works and also verifies every logical units, programmer’s bugs are significantly reduced resulting more time coding, less time debugging.
  • TDD builds developer’s Confidence
    you can confidently refactor your production code without worrying about breaking it, if you already have test code written, it acts as safety net.
  • TDD provides working specification
    Tests on TDD describes the behavior of the code you are going to write. So, tests provides better picture of specification then documentation written on a paper because test runs.
    • TDD enables integration more often allowing larger team to work on same code base
    • TDD guarantees testability
    • TDD reduces product delivery time
    • TDDproduces highly cohesive and loosely coupled Systems
    • TDD simplifies the design
  • Conclusion
    Q &A