Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.

Slides:



Advertisements
Similar presentations
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Advertisements

A Brief Introduction to Test- Driven Development Shawn M. Jones.
Test-Driven Development. Why Testing is Important? “If you don’t have tests, how do you know your code is doing the thing right and doing the right thing?”
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
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.
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.
CS 2110 Software Design Principles II Based on slides originally by Juan Altmayer Pizzorno port25.com.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
Test-Driven Development “Test first, develop later!” –OCUnit.
Test Driven Development Derived from Dr. Fawcett’s notes Phil Pratt-Szeliga Fall 2009.
TDD,BDD and Unit Testing in Ruby
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
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.
Testing in Extreme Programming
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Refactoring Improving the structure of existing code Refactoring1.
Junit At the forefront of Test Driven Development.
Refactoring1 Improving the structure of existing code.
Advanced Programming in Java
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.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
A tool for test-driven development
Claims-Based Identity Solution Architect Briefing zoli.herczeg.ro Taken from David Chappel’s work at TechEd Berlin 2009.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
JUnit Don Braffitt Updated: 10-Jun-2011.
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
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,
Software testing techniques Software testing techniques Software Testability Presentation on the seminar Kaunas University of Technology.
Dave Lloyd Unit Testing in the Real World.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
1 Presentation Title Test-driven development (TDD) Overview David Wu.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
Refactoring1 Improving the structure of existing code.
Refactoring. 2 Process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal.
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
Module 9. Dealing with Generalization Course: Refactoring.
CS223: Software Engineering Lecture 18: The XP. Recap Introduction to Agile Methodology Customer centric approach Issues of Agile methodology Where to.
Google C++ Testing Framework Part 2: Assertion. Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect.
CSCE 240 – Intro to Software Engineering Lecture 3.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Principles and examples
Programming Studio, Fall 2017 Tanzir Ahmed
Unit Testing - solid fundamentals
Test-Driven Development
Architecture Patterns and Refactoring
Smalltalk Testing - SUnit
TDD Overview CS 4501/6501 Software Testing
Test-first development
Test Driven development
Test Driven development
Improving the structure of existing code
Test Driven Development
Test Driven Development
CPSC 315 – Programming Studio Spring 2017
Refactoring.
Presentation transcript:

Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009

Testing Discussed before, general ideas all still hold Test-Driven Development Generally falls under Agile heading A style of software development, not just a matter of testing your code Enforces testing as part of the development process

Test Driven Development Overview Repeat this process: 1. Write a new test 2. Run existing code against all tests; it should generally fail on the new test 3. Change code as needed 4. Run new code against tests; it should pass all tests 5. Refactor the code

Test Writing First Idea is to write tests, where each test adds some degree of functionality Passing the tests should indicate working code (to a point) The tests will ensure that future changes don’t cause problems

Running Tests Use a test harness/testing framework of some sort to run the tests A variety of ways to do this, including many existing frameworks that support unit tests JUnit is the most well-known, but there is similar functionality across a wide range of languages

Test framework Specify a test fixture Basically builds a state that can be tested Set up before tests, removed afterward Test suite run against each fixture Set of tests (order should not matter) to verify various aspects of functionality Described as series of assertions Runs all tests automatically Either passes all, or reports failures Better frameworks give values that caused failure

Mock Objects To handle complex external queries (e.g. web services), random data, etc. in testing Implements an interface that provides some functionality Can be complex on their own – e.g. checking order of calls to some object, etc. Can control the effect of the interface

Example Mock Object Remote service Interface to authenticate, put, get Put and Get implementations check that authentication was called Get verifies that only things that were “put” can be gotten. As opposed to an interface that just returned valid for authenticate/put, and returned fixed value for get.

Successful Tests Tests should eventually pass You need to check that all tests for that unit have passed, not just the most recent.

Refactoring As code is built, added on to, it becomes messier Need to go back and rewrite/reorganize sections of the code to make it cleaner Do this on a regular basis, or when things seem like they could use it Only refactor after all tests are passing Test suite guarantees refactoring doesn’t hurt.

Refactoring Common Operations Extract Class Extract Interface Extract Method Replace types with subclasses Replace conditional with polymorphic objects Form template Introduce “explaining” variable Replace constructor with “factory” method Replace inheritance with delegation Replace magic number with symbolic constant Replace nested conditional with guard clause

Example

Resources Test-Driven Development By Example Kent Beck; Addison Wesley, 2003 Test-Driven Development A Practical Guide David Astels; Prentice Hall, 2003 Software Testing A Craftsman’s Approach (3 rd edition) Paul Jorgensen; Auerback, 2008 Many other books on testing, TDD, also