Test Driven development

Slides:



Advertisements
Similar presentations
SPL/2010 Test-Driven Development (TDD) 1. SPL/
Advertisements

Karel J Robot Chapter 6.
Based on Java Software Development, 5th Ed. By Lewis &Loftus
A practical guide John E. Boal TestDrivenDeveloper.com.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
Chapter 21 Test Driven development. TDD Write the test first Show that test fails Write code to pass the test Run whole suite of tests! This is unit testing.
A Java API Package java.security  The Java Security Package contains classes and interfaces that are required by many Java programs.  This package is.
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program Modules in C 5.3Math Library Functions 5.4Functions.
1 Classes, Encapsulation, Methods and Constructors Class definitions Scope of Data –Instance data –Local data The this Reference Encapsulation and Java.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
Using TDD Making code maintainable, reusable and readable by writing tests.
Test Driven Development Derived from Dr. Fawcett’s notes Phil Pratt-Szeliga Fall 2009.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Introduction to Testing 1. Testing  testing code is a vital part of the development process  the goal of testing is to find defects in your code  Program.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Refactoring Improving the structure of existing code Refactoring1.
Improving the Quality of Existing Code Svetlin Nakov Telerik Corporation
Refactoring1 Improving the structure of existing code.
Advanced Programming in Java
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 21 Test-Driven Development 1CS6359 Fall 2011 John Cole.
Refactoring 101 William C. Wake
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development (TDD)
Sadegh Aliakbary Sharif University of Technology Spring 2011.
1 Presentation Title Test-driven development (TDD) Overview David Wu.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Henrik Bærbak Christensen1 Test Driven Development “TDD” Summary.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
Chapter 3: User-Defined Functions I
Unit testing Java programs1 Unit testing Java programs Using JUnit 4 “If it isn't tested, it doesn’t work”
Refactoring1 Improving the structure of existing code.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
1 Classes, Encapsulation, Methods and Constructors Class definitions Scope of Data –Instance data –Local data The this Reference Encapsulation and Java.
Classes - Intermediate
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Mapping Designs to Code. It specify how to map the design into object oriented language The UML artifacts created during the design work, the interaction.
Lecture 5: Test-Driven Development Basics
Unit Testing with JUnit
Test-driven development
Chapter 6: User-Defined Functions I
Methods Chapter 6.
Using Base Ten Blocks to Make Numbers to 100
© 2016 Pearson Education, Ltd. All rights reserved.
Test Driven development
Chapter 6 - Functions Outline 5.1 Introduction
Test-driven development (TDD)
Unit 3 - The while Loop - Extending the Vic class - Examples
Improving the structure of existing code
TDD & ATDD 1/15/2019.
Test Driven Development
Test Driven Development
Test Driven Lasse Koskela Chapter 3: Refactoring in Small Steps
Refactoring.
Presentation transcript:

Test Driven development Chapter 21 Test Driven development

Write code to pass the test Run whole suite of tests! TDD Write the test first Show that test fails Write code to pass the test Run whole suite of tests! This is unit testing

Programmer satisfaction Clarification of interface and behavior Why? Testing gets done! Programmer satisfaction Clarification of interface and behavior Provable repeatable verification Confidence to change things

NO such thing as a complete and perfect test (No free lunch!) Warning NO such thing as a complete and perfect test (No free lunch!)

Many ide’s support jUnit testing Requires adding library Books shows jUnit 3 jUnit version 4: @org.junit.Test – method annotation Assert methods: assertEquals(“msg”,param1,param2)

Fig. 21.1

Four listed in the test: Extract method Extract constant Refactoring Four listed in the test: Extract method Extract constant Introduce Explaining variable Replacer constructor with factory

Fig. 21.2 public class Player { private Piece piece; private Board board; private Die[] dice; // … public void takeTurn() // roll dice int rollTotal = 0; for (int i = 0; i < dice.length; i++) dice[i].roll(); rollTotal += dice[i].getFaceValue(); } Square newLoc = board.getSquare(piece.getLocation(), rollTotal); piece.setLocation(newLoc); } // end of class

Fig. 21.3 Extract Method public class Player { private Piece piece; private Board board; private Die[] dice; // … public void takeTurn() // the refactored helper method int rollTotal = rollDice(); Square newLoc = board.getSquare(piece.getLocation(), rollTotal); piece.setLocation(newLoc); } private int rollDice() int rollTotal = 0; for (int i = 0; i < dice.length; i++) dice[i].roll(); rollTotal += dice[i].getFaceValue(); return rollTotal; } // end of class

Fig. 21.4 // good method name, but the logic of the body is not clear boolean isLeapYear( int year ) { return ( ( ( year % 400 ) == 0 ) || ( ( ( year % 4 ) == 0 ) && ( ( year % 100 ) != 0 ) ) ); }

Fig. 21.5 // that’s better! boolean isLeapYear( int year ) { boolean isFourthYear = ( ( year % 4 ) == 0 ); boolean isHundrethYear = ( ( year % 100 ) == 0); boolean is4HundrethYear = ( ( year % 400 ) == 0); return ( is4HundrethYear || ( isFourthYear && ! isHundrethYear ) ); }

Fig. 21.6

Fig. 21.7

TDD requires some paractice, but it can be powerful Summary TDD requires some paractice, but it can be powerful Refactoring is a good approach to clean up!