Presented by Bill Wake & S teve Metsker OOPSLA 2004 Copyright is held by the author/owner(s). OOPSLA'04, October 24-28, 2004, Vancouver, British Columbia,

Slides:



Advertisements
Similar presentations
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Advertisements

What is Unit Testing? How TDD Works? Tsvyatko Konov Telerik Corporation
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
A Brief Introduction to Test- Driven Development Shawn M. Jones.
TEST-DRIVEN DEVELOPMENT Lecture 3. Definition Test-driven development (development through testing) is a technique of programming, in which the unit tests.
CIT 590 Intro to Programming Java lecture 3. Hashmaps The equivalent of python dictionaries. With both ArrayLists and Hashmaps, the syntax only allows.
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
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.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
Unit testing C# classes “If it isn’t tested it doesn’t work” Unit testing C# classes1.
Test-Driven Development With Visual Studio 2005 Erno de Weerd Info Support.
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.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Phoenix Software Projects Larry Beaty © 2007 Larry Beaty. Copying and distribution of this document is permitted in any medium, provided this notice is.
October, 2006 © Copyright 2006, Larry A. Beaty. Copying and distribution of this document is permitted in any medium, provided this notice is preserved.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Refactoring Improving the structure of existing code Refactoring1.
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Refactoring1 Improving the structure of existing code.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
Advanced Programming in Java
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Introduction to Refactoring Jim Cooper Falafel Software.
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.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
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 101 William C. Wake
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
A tool for test-driven development
Module 3. Smells Between Classes Course: Refactoring.
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 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
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,
Henrik Bærbak Christensen1 Test Driven Development “TDD” Summary.
Object Oriented Software Development 4. C# data types, objects and references.
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
Refactoring1 Improving the structure of existing code.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
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.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Principles and examples
Module Road Map Refactoring Why Refactoring? Examples
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
TDD Overview CS 4501/6501 Software Testing
Unit testing C# classes
Small changes to code to improve it
Test Driven Development
Test-driven development (TDD)
Arrays in Java What, why and how Copyright Curt Hill.
Improving the structure of existing code
Small changes to code to improve it
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Java Programming Language
Refactoring.
Presentation transcript:

presented by Bill Wake & S teve Metsker OOPSLA 2004 Copyright is held by the author/owner(s). OOPSLA'04, October 24-28, 2004, Vancouver, British Columbia, Canada ACM 04/0010

2 OOPSLA 2004 Premise oYou want to learn: ~test-driven development oyou are hip to learning by doing oYou have access to a Development environment ~for either Java, Visual Basic, or C#

3 OOPSLA 2004 Why TDD? oTest-Driven Development ~Gets you focused on developing exactly what you need ~Produces a very tight linkage between requirements, testing, and development ~Guarantees that when development is done, unit-testing is also done

4 OOPSLA 2004 And Refactoring? oInternally your code can be in terrible shape and yet look completely healthy externally oRefactoring ~Improves the health of code without altering its function ~Makes maintenance easier ~Tends to lead to simple, clean design

5 OOPSLA 2004 Plan for Today! oTest-First Development ~tdd flow chart ~Introducing a problem domain ~introducing x-unit, and Getting NUnit/JUnit running on your machine ~Writing lots of tests -- and making them pass oCooldown oRefactoring ~What it is ~Some Important techniques ~Clean up the Goal System ~Long Method ~Long Method (again!) ~Primitive Obsession ~Feature Envy oCooldown

6 OOPSLA 2004 Test-Driven! Choos e task N y Y Write a new, small test Implement just enough so that the test will fail n implement just enough so that tests should pass Refactor Done ? green ? code smells ? n y run tests

7 OOPSLA 2004 The Domain oA Goal management system ~lets you ~establish goals ~monitor progress against goals ? GoalActual

8 OOPSLA 2004 xUnit oFree(!) software from and ooriginally developed as JUnit by kent beck and erich gamma oa framework for writing and running tests ~an Assertion class to use, to pick up Assert() and other methods ~Attributes, that mark methods as test methods ~a gui oAnd now, A wee demo:

9 OOPSLA 2004 Go! ocompile testgoal. vb, TestGoal.cs, or TestGoal.java orun testgoal ~get a red bar ~w00t oImplement just enough (in Goal. vb/cs/java and Actual. vb/cs/java) to get a green bar ~Really: just enough!

10 OOPSLA 2004 Stoke it up! oGet 7 tests red-then-green to earn a prize! oyer the customer, but … here are some good tests ~multiple actuals applied to a goal ~do not meet goal if sum of actuals < goal ~do meet goal if sum of actuals >= goal ~no negative times (or zero) on actuals or goals ~goals with temporal element ~actuals after goal datetime do not apply to goal ~goal is met by actuals that do not exceed the goal ~sum of actuals <= goal ~as in spending

11 OOPSLA 2004 More Tests! oelaborate ~think like a unit tester ~cover any case you have missed omore features ~monitor goals other than minutes applied ~like, run a mile in 5 minutes ~or run so many miles ~goals with dependencies ~milestone-y goals ~like, meet 5 times before Christmas ~add notes ~horseshoe goals (being close counts) ~checkbook goals

12 OOPSLA 2004 Cooldown oDebrief ~One surprising thing about tdd? oCould you use this at work? owhat about the internal health of the code? Does it matter? Can we improve it?

14 OOPSLA 2004 Refactoring oIn practice, TDD applies refactoring consistently oRefactoring ~a transformation that improves code but doesn ’ t change its effect oSmell ~a potential problem in code oExperience?

15 OOPSLA 2004 A Few refactorings oRefactorings that Address common smells: ~Long Method ~Primitive Obsession ~Feature Envy oCheck out Martin Fowler ’ s book "Refactoring" for lots of smells and refactorings

16 OOPSLA 2004 The Domain oA Goal vs. Actual tracking system oEnhanced to count actuals ~if they occur before the goal ~if they contain one of the goal's keywords

17 OOPSLA 2004 Example: Long Method Imports System.Text.RegularExpressions Public Class Goal... Public Function met() As Boolean Dim keys As New ArrayList Dim keyword As String For Each keyword In Regex.Split(sKeywords, ",") keys.Add(keyword.Trim()) Next keyword... End Function End Class

18 OOPSLA 2004 Public Function met() As Boolean... Dim a As Actual For Each a In actuals If dtDeadline.CompareTo(a.WhenOccurred) >= 0 Then Dim k As String For Each k In keys Dim desc As String desc = a.Description desc = desc.ToLower Dim lowK As String lowK = k.ToLower() Dim i As Integer i = desc.IndexOf(lowK) If i >= 0 Then fits = True End If Next End If If fits Then sum = sum + a.Quantity End If Next Return sum >= dQuantity End Function

19 OOPSLA 2004 You Gotta Long Method? oApply Extract Method! ~Create a stub for the new method. ~Copy code to the new method. ~Adjust the new method: some variables are temporaries, others are parameters, and others may become return values. ~Compile. ~Replace the old code with a call to the new method. ~Compile and test.

20 OOPSLA 2004 Feature Envy o"A method that seems more interested in a class other than the one it is actually in." --Refactoring, Fowler et al. oSimilar to Law of Demeter ~which we might trivialize as a.b.c

21 OOPSLA 2004 Feature Envy In Our Code oShould "fits" be a behavior for goal or actual? oMove this behavior to Actual ~and see if it feels (or smells) any better

22 OOPSLA 2004 Feature Envy? oApply Move Method! ~Decide which method(s) should move. ~Declare the method in the target. ~Copy code from the source method to the target method. ~Adjust the target method. (You may have to pass in a reference to the source if the new method uses some features from it.) ~Compile. ~Ensure the source can find the proper target (via some variable.) ~Make the source method delegate to the target method. ~Compile and test. ~You may want to inline references to the target so you can remove the delegating method. ~Compile and test.

23 OOPSLA 2004 Further Refactorings oAt this point, there are many possible improvements oYou may see string manipulation methods used to excess - this may be primitive obsession ~If you get this far, you might want to use Martin's formula for removing Primitive Obsession

24 OOPSLA 2004 Primitive Obsession? oApply Replace Data Value with Object! ~Create the new class: ~Make the data value a final field. (This makes the new class start as a value type rather than a reference type.) ~Give the class a constructor that stores the data value in the field. ~Give the class a getter for the field. ~Compile. ~In the old class, make the type of the data value field be the new class. ~In the old class, make any assignment call the new constructor. If the field is assigned, create a new instance of the new class. ~Compile and test

25 OOPSLA 2004 Go! oExtract a tokenizeKeywords() method! oExtract a fits() method! oMove fits() to the Actual class! oLook for primitive obsession and other smells!

26 OOPSLA 2004 Extra Reps oapply true tdd: ~Red bar, green bar, and refactor oAnother feature - Composite Goals ~a goal that would support passing the xyz certification exam ~Allow for a goal to be composed of subgoals (and so on recursively)

27 OOPSLA 2004 Cooldown oDebrief ~What was one surprising or interesting thing about Refactoring? oWhere to? ~Finish your goal manager! ~Check out Bill's book, and Martin's

28 OOPSLA 2004 Resources oBeck, Kent. Test-Driven Development: By Example oNewkirk & Vorontsov: Test-Driven Development in Microsoft.Net oFowler, Martin, et al. Refactoring: Improving the Design of Existing Code, Addison-Wesley, oWake, William C. Refactoring Workbook, Addison-Wesley, 2003.

Thanks!