Test Driven Lasse Koskela Chapter 3: Refactoring in Small Steps

Slides:



Advertisements
Similar presentations
Chapter 6 Writing a Program
Advertisements

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 17 Templates.
Clean code. Motivation Total cost = the cost of developing + maintenance cost Maintenance cost = cost of understanding + cost of changes + cost of testing.
A practical guide John E. Boal TestDrivenDeveloper.com.
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.
E-commerce Project Erik Zeitler Erik Zeitler2 Lab 2  Will be anounced and scheduled later  We will deploy Java Server Pages on a Tomcat server.
16-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
true (any other value but zero) false (zero) expression Statement 2
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
28-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
TDD OVERVIEW OF TEST DRIVEN DEVELOPMENT by Paul M. code of the damned. com.
Intro to Generic Programming Templates and Vectors.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
TDD,BDD and Unit Testing in Ruby
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Effective Java: Generics Last Updated: Spring 2009.
Software testing techniques Software testing techniques Mutation testing Presentation on the seminar Kaunas University of Technology.
Best Practices. Contents Bad Practices Good Practices.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 1 Simplifying Conditionals Steve Chenoweth Office Phone: (812) Cell: (937)
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 2 Overloaded Operators, Class Templates, and Abstraction Jeffrey S. Childs Clarion University.
Module 6 – Generics Module 7 – Regular Expressions.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Chapter 21 Test-Driven Development 1CS6359 Fall 2011 John Cole.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
Type Abstraction SWE Spring October 05Kaushik, Ammann Substitution Principle “In any client code, if supertype object is substituted.
Chapter 2 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 2-1 Solving Linear.
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,
TDD Example Test Driven – Koskela Chapter 2. Mail Template Test List 1.Evaluating template “Hello, ${name}” with the value “Reader” for variable “name”
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Refactoring. DCS – SWC 2 Refactoring ”A change made to the internal structure of software to make it easier to understand and cheaper to modify without.
Module 9. Dealing with Generalization Course: Refactoring.
State ● What is state? ABCDE. State and Data Structures ABCDE A B C D E ● Data structures encode state. In doing so, they introduce state ● State of data.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Catalog of Refactoring (6) Making Method Calls Simpler.
Refactoring Presentation Yash Pant. Overview 3 Refactoring Types: 1. Replace Error Code with Exception 2. Split Temporary Variable 3. Remove Middle Man.
Refactoring (1). Software Evolution Cope with change Feature bloat Design decay Code duplications “Pattern time is refactoring time” Make future changes.
CO4301 – Advanced Games Development Week 1 Introduction
TK1924 Program Design & Problem Solving Session 2011/2012
Paul Ammann & Jeff Offutt
Test-driven development
Module Road Map Refactoring Why Refactoring? Examples
Lecture 14 Throwing Custom Exceptions
COMP261 Lecture 18 Parsing 3 of 4.
Selection (also known as Branching) Jumail Bin Taliba by
Mutation testing Julius Purvinis IFM-0/2.
TDD Overview CS 4501/6501 Software Testing
Clone Refactoring with Lambda Expressions
Microsoft Ignite NZ October 2016 SKYCITY, Auckland.
Lecture 11 B Methods and Data Passing
Test Driven Lasse Koskela Chapter 2: Beginning TDD
Overview of Eclipse Lectures
Extending Classes.
Test Driven development
Test Driven development
Introduction to Software Testing (2nd edition) Chapter 4 TDD Example
Building Java Programs
Test Driven Lasse Koskela Chapter 2: Beginning TDD
Functions Chapter 9 Copyright © 2008 W. W. Norton & Company.
Test Driven Lasse Koskela Chapter 3: Refactoring in Small Steps
Testing Acknowledgement: Original slides by Jory Denny.
Test Driven Lasse Koskela Chapter 9: Acceptance TDD Explained
Refactoring Low Level/High Level.
Ian VanBuren Refactoring.
Building Java Programs
Presentation transcript:

Test Driven Lasse Koskela Chapter 3: Refactoring in Small Steps Paul Ammann http://cs.gmu.edu/~pammann/

Overview Exploring a Potential Solution Changing Design in a Controlled Manner Taking the New Design Further The Most Powerful Designs Are Always the Result of a Continuous Process of Simplification and Refinement. 8/10/2019

Recalling the Problem Existing Design Replaced Variables Via Simple Matching For all variables v, replace ${v} with its value: result = result.replaceAll(regex, entry.getValue()) Failing test: @Before sets template value to “${one}, ${two}, ${three}” @Test public void variablesGetProcessedJustOnce() throws Exception { template.set(“one”, “${one}”); template.set(“two”, “${three}”); template.set(“three”, “${two}”); assertTemplateEvaluatesTo(“${one}, ${three}”, ${two}); } Tweaking the Current Design Won’t Make This Test Pass. 8/10/2019

Exploring A Potential Solution Exploring a “Segment” Solution for Templates Prototyping with Spikes A Spike is A Detour to Learn In Template Example, Learning is About regex Learning by Writing Tests Need to Figure Out An API? Write Some Test Code That Uses The API RegexlearningTest Example Spike for Learning an API Note Koskela’s Misunderstanding of the Role of Parentheses Simple Here: We’re Finding Variables in a Template Compiling Regex Patterns, Matching Expressions Get Smarter On The Side, Then Apply 8/10/2019

Changing Design in Controlled Manner Creating an Alternative Implementation Starting With the Low Hanging Fruit TDD Development of a Template Parser Removing Duplication From Tests Refactoring Is Always Important Applying Learning From the Spike Final Code Version (note Segment class, originally String) private void append(String segment, StringBuilder result) { if (isVariable(segment) { evaluateVariable(segment, result); } // dispatching  else { result.append(segment);} } Koskela Refactors Substantially TemplateParse.java Now We Can Parse; Next Step Is To Use Parser 8/10/2019

Changing Design in a Controlled Manner - Continued Switching Over Safely Adopting the New Implementation Recoding the evaluate() method Cleaning Up By Extracting Methods Pull Out The Old Stuff That ‘s No Longer Relevant Result is new Template Class Template.java No New Functionality, But Definitely Refactored 8/10/2019

Taking the New Design Further Keeping Things Compatible Building on Existing Functionality Note equals(), hashCode() treatment in Segment classes Any Worries About This? Segment, PlainText , Variable Refactoring Logic into Objects Tell, Don’t Ask! Motivation for Segment class Making the Switchover Getting Caught By the Safety Net Adding Exceptional Behavior! Deleting Dead Code and Further Clean Up Test Set Makes Requirements Concrete 8/10/2019