Sadegh Aliakbary Sharif University of Technology Spring 2012.

Slides:



Advertisements
Similar presentations
A practical guide John E. Boal TestDrivenDeveloper.com.
Advertisements

Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
A Brief Introduction to Test- Driven Development Shawn M. Jones.
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
Refactoring By: Brian Smith. What is Refactoring? Definition: a change to the internal structure of software to make it easier to understand and cheaper.
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
JUnit. Why is testing good? Due to psychological factors, programmers are bad testers. A computer can test much faster than a human Philosophy: “If it.
XP and Refactoring David Talby. Development Methodologies The Software Crisis – 84% of software projects are not on time – 31% of software projects never.
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.
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.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Refactoring Lecture 5 CIS 6101 Software Processes and Metrics.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Unit Testing.
Advanced Programing practices
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
Testing in Extreme Programming
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
Refactoring1 Refactoring DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY February 6, 2009.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
Refactoring1 Improving the structure of existing code.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
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.
JUnit Adam Heath. What is JUnit?  JUnit is a unit testing framework for the Java programming language  It allows developers to swiftly and easily test.
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
A tool for test-driven development
Abstraction ADTs, Information Hiding and Encapsulation.
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.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 1 Refactoring Principles Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
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,
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
1 ECE 750 Topic 8 Meta-programming languages, systems, and applications Evolving Object-Oriented Designs with Refactorings – Lance Tokuda and Don Batory.
Refactoring Mehdi Einali Advanced Programming in Java 1.
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
Refactoring1 Improving the structure of existing code.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
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?
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
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.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Principles and examples
Unit Testing.
Module Road Map Refactoring Why Refactoring? Examples
A Very Common Series of Techniques
Advanced Programming in Java
Refactoring II 21-Sep-18.
Advanced Programming Behnam Hatami Fall 2017.
بازآرایی برنامه Code Refactoring
Improving the structure of existing code
Advanced Programming Behnam Hatami Fall 2017.
Advanced Programming Behnam Hatami Fall 2017.
Refactoring II 5-Feb-19.
Refactoring.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Advanced Programing practices
Refactoring.
Presentation transcript:

Sadegh Aliakbary Sharif University of Technology Spring 2012

Review Java Programming Language Principles of Object Oriented Programming Characteristics of objects Encapsulation Objects in memory References Heap Stack Parameter Passing Spring 2012Sharif University of Technology2

Review (2) Initialization and Cleanup Constructor finalize() Order of initialization Initialization blocks Access specifiers Public Private Package access Spring 2012Sharif University of Technology3

Review (3) Package Static The this reference Method overloading toString() equals() Refactoring Bad smells Refactoring techniques Spring 2012Sharif University of Technology4

Agenda Software Quality Characteristic of a good software Test Unit Testing Refactoring Spring 2012Sharif University of Technology5

Quality of Product The producer should ensure about the quality of the products Quality Control Any business, any product Spring 2012Sharif University of Technology6

A Cook Spring 2012Sharif University of Technology7

In surgery Spring 2012Sharif University of Technology8

A Car Maker Spring 2012Sharif University of Technology9

Quality Control Quality should be tested A product is not finalized, before the test Different kinds of test, check different kinds of quality Spring 2012Sharif University of Technology10

Software Quality We are programmers Programmers produce software What are characteristics of a good software? Many parameters. E.g. Conformance to requirements Performance Time Memory Maintainability Changeability Different kinds of test, check different kinds of quality Spring 2012Sharif University of Technology11

Test in Other Industries Test side effects A damage to the product Test of a building Test of a car Test of a part of a product Spring 2012Sharif University of Technology12

Test Side Effects Spring 2012Sharif University of Technology13

What to do with Test Side Effects? Testing a sample of the product Simulation Mathematical analysis In software testing Along with all of these techniques And we can also test the software itself! (Usually) no damage to the software Spring 2012Sharif University of Technology14

Test Target System Test Test the system as a whole For performance, correctness and conformance. Unit Test Test the units and modules Test of a component Test of a class Test of a method Spring 2012Sharif University of Technology15

How to Test Software Manual Test Try it! Test Tools Performance Test Profiling JProfiler, TPTP Load Test Jmeter Test Code Unit Tests Test Teams Spring 2012Sharif University of Technology16

Test Code Business Code The code, written for implementation of a requirement Test Code The code, written for test of an implementation Spring 2012Sharif University of Technology17

Unit Testing A process for the programmer Not a test team procedure For improving the code quality Reduces bugs Test of units of software before the software is completed Unit: method, class Spring 2012Sharif University of Technology18

Classical Unit Testing Writing main() method Some printlns Drawbacks? Spring 2012Sharif University of Technology19

Drawbacks 1. Test code coupled with business code In the same class 2. Written tests are discarded 3. One test at a time 4. The programmer executes the tests himself Test execution is not automatic 5. The programmer should check the result of each test himself The test is passed or failed? The test result interpretation is not automatic Spring 2012Sharif University of Technology20

A Good Unit Test Code Repeatable Automatic Invocation Acceptance (Pass/Failure) JUnit helps you write such tests Spring 2012Sharif University of Technology21

JUnit, First Example Spring 2012Sharif University of Technology22

JUnit, The Green Bar Spring 2012Sharif University of Technology23

public class Testing public void testNormal() { int[] array = {3,2,1,4}; int[] sorted = {1,2,3,4}; Business.sort(array); for (int i = 0; i < sorted.length; i++) { Assert.assertEquals(sorted[i], array[i]); public void testEmptyArray() { int[] array = {}; try{ Business.sort(array); }catch(Exception e){ Assert.fail(); } Assert.assertNotNull(array); Assert.assertEquals(array.length, 0); } Spring 2012Sharif University of Technology24

Assertions assertNull(x) assertNotNull(x) assertTrue(boolean x) assertFalse(boolean x) assertEquals(x, y) Uses x.equals(y) assertSame(x, y) Uses x ==y assertNotSame fail() Spring 2012Sharif University of Technology25

Spring 2012Sharif University of Technology26

Spring 2012Sharif University of Technology27

A Good Unit Test is Automated Through Repeatable Independence Professional Spring 2012Sharif University of Technology28

Test Driven Development Test First Development Before writing a code, write the tests! Spring 2012Sharif University of Technology29

TDD Spring 2012Sharif University of Technology30

Refactoring A disciplined way to restructure code In order to improve code quality Without changing its behavior a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. Spring 2012Sharif University of Technology32 Martin Fowler

Refactoring Refactoring is the process of changing a software system In such a way that it does not alter the external behavior of the code But improves its internal structure It is a disciplined way to clean up code It minimizes the chances of introducing bugs When you refactor, you are improving the design of the code after it has been written. Spring 2012Sharif University of Technology33 Martin Fowler

Refactoring By continuously improving the design of code, we make it easier and easier to work with Spring 2012Sharif University of Technology34 Joshua Kerievsky, Refactoring to Patterns

The Two Hats Kent Beck's metaphor of two hats Divide your time between two distinct activities adding function refactoring Spring 2012Sharif University of Technology35

Why Should I Refactor? Refactoring Improves the Design of Software Refactoring Makes Software Easier to Understand Refactoring Helps You Find Bugs Refactoring Helps You Program Faster Refactoring makes your code more maintainable Spring 2012Sharif University of Technology36

When Should You Refactor? The Rule of Three: Refactor When You Add Function Refactor When You Need to Fix a Bug Refactor As You Do a Code Review Spring 2012Sharif University of Technology37

Bad Smell A bad smell in code Any symptom in the source code that possibly indicates a deeper problem. The term is coined by Kent Beck. Spring 2012Sharif University of Technology38

Bad Smells If it stinks, change it! Kent Beck and Martin Fowler. Bad smells in code Bad smells are source of problems Remove bad smells How? By Refactoring Spring 2012Sharif University of Technology39

Bad Smells Duplicated Code Long Method Large Class Long Parameter List … Spring 2012Sharif University of Technology40

Refactoring Techniques Extract Method Move Method Variable Class Extract Class Rename Method Variable Class Pull Up Push Down Spring 2012Sharif University of Technology41

IDE Support Refactoring techniques are widely supported by IDEs Practice it in Eclipse Spring 2012Sharif University of Technology42

Reference Refactoring: improving the design of existing code, Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts (1999) Spring 2012Sharif University of Technology43

Spring 2012Sharif University of Technology44