Test Driven Development An approach to writing better code Jimmy Zimmerman Intel Corporation.

Slides:



Advertisements
Similar presentations
Test-First Programming. The tests should drive you to write the code, the reason you write code is to get a test to succeed, and you should only write.
Advertisements

Extreme Programming Alexander Kanavin Lappeenranta University of Technology.
Javascript Code Quality Check Tools Javascript Code Quality Check Tools JavaScript was originally intended to do small tasks in webpages, but now JavaScript.
What is Unit Testing? How TDD Works? Tsvyatko Konov Telerik Corporation
Systems Analysis, Prototyping and Iteration Systems Analysis.
Smalltalk Connections 1 Test Driven Development (TDD) Presented by Victor Goldberg, Ph.D.
TEST-DRIVEN DEVELOPMENT Lecture 3. Definition Test-driven development (development through testing) is a technique of programming, in which the unit tests.
PS4: Test Driven Development Based on Test Driven Development by Example By Kent Beck.
Software Quality Assurance Inspection by Ross Simmerman Software developers follow a method of software quality assurance and try to eliminate bugs prior.
Programming Creating programs that run on your PC
EXtreme.NET Dr. Neil Roodyn. eXtreme.NET Who is Dr. Neil? MISSION: To increase the value of your Software Business Working with software for way too long.
1 IS371 WEEK 8 Last and Final Assignment Application Development Alternatives to Application Development Instructor Online Evaluations.
Computer Engineering 203 R Smith Agile Development 1/ Agile Methods What are Agile Methods? – Extreme Programming is the best known example – SCRUM.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
CSC 395 – Software Engineering Lecture 21: Overview of the Term & What Goes in a Data Dictionary.
Xtreme Programming. Software Life Cycle The activities that take place between the time software program is first conceived and the time it is finally.
Maintenance = Software Evolution Any changes after the client has accepted the product is considered maintenance. n Any Changes? n What might these be?
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
Test-Driven Development “Test first, develop later!” –OCUnit.
Test Driven Development Derived from Dr. Fawcett’s notes Phil Pratt-Szeliga Fall 2009.
By for Test Driven Development: Industry practice and teaching tool Robert Vanderwall, Ph.D. 1 WISTPC-15.
TDD,BDD and Unit Testing in Ruby
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
Chapter 7 Software Engineering Objectives Understand the software life cycle. Describe the development process models.. Understand the concept of modularity.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
Extreme Programming(XP)
Describing Methodologies PART II Rapid Application Development* Systems Analysis and Design II.
CS 360 Lecture 3.  The software process is a structured set of activities required to develop a software system.  Fundamental Assumption:  Good software.
Teaching material for a course in Software Project Management & Software Engineering – part II.
Software Software is omnipresent in the lives of billions of human beings. Software is an important component of the emerging knowledge based service.
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
BTEC Unit 06 – Lesson 08 Principals of Software Design Mr C Johnston ICT Teacher
Chapter 7 Software Engineering Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Software Engineering Chapter 3 CPSC Pascal Brent M. Dingle Texas A&M University.
Chapter 7 The Practices: dX. 2 Outline Iterative Development Iterative Development Planning Planning Organizing the Iterations into Management Phases.
Test-Driven Development Eduard Miric ă. The problem.
BEHAVIOR DRIVEN TEST DEVELOPMENT Specification by Example.
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
Program Development Cycle
1 Presentation Title Test-driven development (TDD) Overview David Wu.
Click to add text Systems Analysis, Prototyping and Iteration.
(1) Test Driven Development Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Extreme Programming. Extreme Programming (XP) Formulated in 1999 by Kent Beck, Ward Cunningham and Ron Jeffries Agile software development methodology.
Software Development Process CS 360 Lecture 3. Software Process The software process is a structured set of activities required to develop a software.
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
CS223: Software Engineering Lecture 18: The XP. Recap Introduction to Agile Methodology Customer centric approach Issues of Agile methodology Where to.
Northwest Arkansas.Net User Group Jay Smith Tyson Foods, Inc. Unit Testing nUnit, nUnitAsp, nUnitForms.
Software Development. The Software Life Cycle Encompasses all activities from initial analysis until obsolescence Analysis of problem or request Analysis.
MANAGEMENT INFORMATION SYSTEM
TDD Unit tests from a slightly different point of view Katie Dwyer.
Software Development - Methodologies
Software Development.
AP CSP: Creating Functions & Top-Down Design
“When quality is critical"
Test-driven development
Chapter - 8 Implementation.
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
The Software Development Cycle
Software Engineering (CSE 314)
Johanna Rothman Create Technical Excellence Chapter 9
Software life cycle models
Test-driven development (TDD)
Test Driven Lasse Koskela Chapter 9: Acceptance TDD Explained
Test-Driven Development
TDD & ATDD 1/15/2019.
Applied Software Project Management
Test-Driven Development
The Software Development Cycle
Presentation transcript:

Test Driven Development An approach to writing better code Jimmy Zimmerman Intel Corporation

Outline What is TDD? Why perform TDD? Myths about TDD How do we do TDD? When NOT to perform TDD Tools for TDD Example of TDD Q&A

The Problem Over 50% of all software projects are initiated and then canceled. Over 80% of software projects completed suffer massive * cost and time overruns. Quality, or the lack thereof, is a major issue. Code is bloated, buggy, and marginally useful. * Over 100% of budget and/or time. West, pg 87

The Solution (Isn’t) building / using new tools. creating more elaborate documents. adding more layers of process “better” programming languages

The Solution (is) producing “better people” aka Better Programmers, regardless of method or intended use of the application.

FACT 1 The most important factor in software work is not the tools and processes used by the programmers but rather the quality of the programmers themselves.

I. What is TDD? Definition: Test Driven Development is the practice of utilizing tests to document and define the behavior of software. Tests DRIVE the design of software, not follow already designed software. Design documentation is finalized from the tests, not used to create the tests from.

FACT 2 The most important part of writing programs is creating the tests that describe the behavior of the software and not the software itself.

II. Why perform TDD? Eliminates Duplication of Code Shared Responsibility Common Language Simplest Solution Possible Modularization A “Gateway Habit”

Eliminates Duplication of Code Code duplication epitomizes bad software. Tests describe the behavior of the code we are writing. When writing the code, we will find common behavior and refactor. Tests provide the ability to reliably refactor existing code. Tests ensure the behavior of the code does not change after refactoring.

Shared Responsibility Application code is the responsibility of all programmers on a project. Code that is unfamiliar to a programmer is hard to learn. Tests document the behavior of code, making it easier to learn. A test allows the code to be modified by any developer. This prevents “pigeon-holing” and overall increases speed of development. The more peer review of code by the greatest number of programmers the better.

Common Language Programs are written in code. The code has a language. Developers understand the language. Code is deterministic. The tests are written with the common language of the application. A single language documents the behavior of the application and the implementation of the behavior. Translations of any kind introduce errors and misunderstandings to the meaning.

Simplest Solution Possible Software is complex. The simpler the code the more resilient and easier it is to change. Tests define requirements. Writing code should satisfy the requirements no less and no more. Every line of code requires maintenance. Adding more code adds to the maintenance by adding complexity. Program for today. Worry about tomorrow when it comes. “Simplest Solution that Works is NOT the first stupid idea that pops into your head” – Udi Dahan

Program for Today (expanded) Q: Why? Isn’t it better to plan for tomorrow? A: No –Planning is not implementing. –Tomorrow might not come. –When you finally need it, you probably will know more about how to do it correctly. –Tests mitigate the cost of change over time.

Cost of Change

FACT 3 Adding features when they are needed saves more money over time than it costs to build before they are needed.

Modularization Good software depends on building small single use modules. While the technology of modules changes (methods, messages, global functions, APIs) each provides a quantifiable set of behaviors. Once you start to TDD, you will find that your code will naturally become more modular to support the ease of testing.

A “Gateway Habit” TDD is the foundation that enables other habits of successful development processes. –Frequent, incremental releases (less is more) –Peer review –Early customer feedback –KISS –Refactoring –Agile methods

III. Myths about TDD 1.It’s just for OOP 2.It’s a replacement for good programming skill 3.It’s hard to do 4.I don’t have time 5.Testing is for QA

Myth 1: It’s just for OOP NO. –TDD is about a mindset and not a technology. –While objects make it easier to program complex applications, all programs benefit from writing tests. They act as an outline for what you want to do. –Tests can work with any language and platform. ( I’ve seen TDD done in x86 assembler at school! )

Myth 2: It’s a replacement for good programming skill NO. –No matter how good you are, you will make a mistake eventually. –Even if you never make mistakes someone else will need to maintain your code. It is unlikely they can know all the behaviors your code has. –This is the most important of all programmer skills and not a replacement for skill!

Myth 3: It’s hard to do INCORRECT. –It makes your job easier by breaking down your work into manageable steps. –It allows you to make changes to existing code easily. –It does take discipline however. ( so yes in that it’s “hard” to not be lazy )

Myth 4: I don’t have time WRONG. –Tests prevent bugs. Less bugs make for more time over the life of the application. –An ounce of prevention is worth a pound of cure. –They allow someone else to help you without making your life harder.

Myth 5: Testing is for QA WRONG. –QA is not there to find bugs. They are there to confirm the behavior of application meets the agreed functionality. –A developer is responsible for writing secure, bug free, and reliable code that provides the exact functionality the program specifies. –A bug should be an exceptionally rare occurrence in QA. Tests are the tool to make them rare.

IV. How do we do TDD? 1.Write the test code. 2.Compile the test code (this should fail) 3.Implement just enough to compile. 4.Run and watch it fail 5.Implement just enough to make the first test pass. 6.Run the test and watch it pass. 7.Refactor for clarity and to eliminate duplication. 8.Repeat from top.

Fact 4 Red -> Green -> Refactor Small verifiable steps are better. They provide immediate feedback that builds confidence in code. When something goes wrong, you will immediately know where and why.

V. When NOT to perform TDD TDD requires an upfront investment in resources. Over the course of a project development cycle this amount of effort is a very small percentage of the overall work. The end of the cycle does not allow the cost to be minimized and therefore it is inappropriate to begin TDD during that phase.

Tools for TDD Tools do not make or break TDD, they only aid it ( remember it’s a mindset ). Tools depend on platform. –nUnit –mbUnit –jUnit –Page tracing –ACT –Invent a tool!

Example of TDD Interactive Example using Visual Studio.Net 2003 and nUnit. Creating an unbounded stack Push/Pop/IsEmpty capability Properly limits bound access

Task 1

Task 2

Task 3