Corrado Aaron Visaggio visaggio@unisannio.it, Research Centre on Software Technology - RCOST University of Sannio Benevento, Italy



Documenti analoghi
Ingegneria del Software

Gestione dello sviluppo software Modelli Agili

REGISTRATION GUIDE TO RESHELL SOFTWARE

Ingegneria del Software Testing. Corso di Ingegneria del Software Anno Accademico 2012/2013

metodologie metodologia una serie di linee guida per raggiungere certi obiettivi

Organizzazione della lezione. Extreme Programming (XP) Lezione 19 Extreme Programming e JUnit. JUnit. JUnit. Test-Driven Development

WELCOME. Go to the link of the official University of Palermo web site Click on the box on the right side Login unico

Poca documentazione: uso di Story Card e CRC (Class Responsibility Collabor) Collaborazione con il cliente rispetto alla negoziazione dei contratti

introduzione al corso di ingegneria del software

Tecnologia e Applicazioni Internet 2009/10

Sviluppo software guidato dal testing. metodologie e strumenti

Introduzione al TDD. Test Driven Development: Quando, Come, Perchè Facoltà di Ingegneria Pavia 27 Novembre Marco Fracassi Roberto Grandi

U Corso di italiano, Lezione Quindici

Università degli Studi di Roma La Sapienza, Facoltà di Ingegneria. Corso di INGEGNERIA DEL SOFTWARE (Ing. Informatica, Nuovo Ordinamento)

UNIVERSITÀ DEGLI STUDI DI TORINO

Portale Materiali Grafiche Tamburini. Grafiche Tamburini Materials Portal

ESERCIZIO 1 Si faccia riferimento all Allegato A - OPS 2016, problema ricorrente REGOLE E DEDUZIONI, pagina 2.

College Algebra. Logarithms: Denitions and Domains. Dr. Nguyen November 9, Department of Mathematics UK

Programmazione ad Oggetti. Programmazione ad Oggetti. JUnit è un ambiente di test per programmi Java. Sviluppato da Kent Beck

Constant Propagation. A More Complex Semilattice A Nondistributive Framework

Downloading and Installing Software Socio TIS

Tecnologia e Applicazioni Internet 2011/12

Si ricorda che il pagamento è possibile solo tramite CARTE DI CREDITO del circuito VISA VBV (Verified By Visa) o MASTERCARD SECURECODE

Si faccia riferimento all Allegato A - OPS 2016, problema ricorrente REGOLE E DEDUZIONI, pagina 2.

UML: Aggregazione. class A { int s; public void sets(int){ }; public int gets() { }; class B {A ob; public void usea() { }; }

User Guide Guglielmo SmartClient

Esercitazione di lunedì - TUTTE LE MATRICOLE -

Introduzione all Ingegneria del Software

CEDMEGA Rev 1.2 CONNECTION TUTORIAL

Finite Model Theory / Descriptive Complexity: bin

Progetto di Informatica III

AIM OF THE LESSON: for the students to familiarise themselves with the language of cooking

extreme Programming in un curriculum universitario

Guida all installazione del prodotto 4600 in configurazione plip

TNCguide OEM Informativa sull introduzione di documentazione aggiuntiva nella TNCguide

CONFIGURATION MANUAL

REGISTRATION. Area Ricerca

Echi da Amsterdam. Titolo: Sintesi presentazioni Metodologia Agile. Sintesi del Leadership Meeting e dell EMEA Congress Relatore: Bruna Bergami

Copyright 2012 Binary System srl Piacenza ITALIA Via Coppalati, 6 P.IVA info@binarysystem.eu

A.A. 2006/2007 Laurea di Ingegneria Informatica. Fondamenti di C++ Horstmann Capitolo 3: Oggetti Revisione Prof. M. Angelaccio

Ministero della Salute Direzione Generale della Ricerca Scientifica e Tecnologica Bando Giovani Ricercatori FULL PROJECT FORM

SANTE PELLEGRINO

Corso di Ingegneria del Software. Introduzione al corso

Introduzione all ambiente di sviluppo

WELCOME UNIPA REGISTRATION:

Customer Centric/Inquiry/E-bill. Tanya Enzminger

Stringhe. Prof. Lorenzo Porcelli

BDM Motorola MC32xxx User Manual

Extreme programming e metodologie agili

Canti Popolari delle Isole Eolie e di Altri Luoghi di Sicilia (Italian Edition)

Agile. mercoledì, 1 luglio 2015, 3:05 p. Prof. Tramontano docente Federico II ingegneria del software. Sviluppo Agile: metaprocesso

Esercizi Programming Contest

Test di unità con JUnit4

Data Alignment and (Geo)Referencing (sometimes Registration process)

SRT064 BTH SRT051 BTH SRT052 BTH

THIS DOCUMENT WILL GUIDE YOU STEP BY STEP THROUGH THE DONATION PROCESS RELATED TO THE CROWDFUNDING CAMPAIGN MADE BY STANZE AL GENIO S HOUSE MUSEUM.

Object Oriented Programming: Inheritance

Scritto da DEApress Lunedì 14 Aprile :03 - Ultimo aggiornamento Martedì 26 Maggio :34

SOA!= OO. Andrea Saltarello Software Managed Designs S.r.l. andrea.saltarello@manageddesigns.it

Single-rate three-color marker (srtcm)

Le cellule staminali dell embrione: cosa possono fare Embryonic stem cells are exciting because they can make all the different types of cell in the

Metodologie Agili per lo sviluppo di applicazioni Internet Distribuite. Agile Group DIEE, Università di Cagliari

START GIEMME. Via Naro, 71 Pomezia (Roma) - Tel Fax mail: info@giemmeitaly.it

Test Driven Development e Pair Programming

Introduzione all Agile Software Development

Convegno Qualità Microbiologica dei Cosmetici: Aspetti Tecnici e Normativi Milano, 15 maggio Lucia Bonadonna Istituto Superiore di Sanità

Guida rapida di installazione

Guida alla configurazione Configuration Guide

Pezzi da ritagliare, modellare e incollare nell ordine numerico indicato.

Graphs: Cycles. Tecniche di Programmazione A.A. 2012/2013

A Solar Energy Storage Pilot Power Plant

INFORMAZIONE AGLI UTENTI DI APPARECCHIATURE DOMESTICHE O PROFESSIONALI

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

click studenti futuri Pag. 1

Temperatura di Lavoro / Working Temperature. Distanza di controllo/ Distance control

Gestione dello sviluppo software Modelli Agili

Programmazione 2 - Marco Ronchetti. Fondamenti di Java. Fac.Scienze Università di Trento. Static

Testing. Esempio. Esempio. Soluzione 1. Fondamenti di Informatica T2 Modulo 2. Università di Bologna A.A. 2008/2009. Come fare???

Capitolo 3 Sviluppo di Programmi Strutturati

A review of some Java basics. Java pass-by-value and List<> references

Qui u ck c k PE P R E L

Examples of chemical equivalence

Prova finale di Ingegneria del software

How to use the WPA2 encrypted connection

JUNIT. Angelo Gargantini Info 3 B 2011

nel mondo del caffè, che spinge in avanti i confini del possibile.

CCTV DIVISION. Guida Alla Lettura del Numero Seriale, Codice Prodotto, Versione Firmware, Versione Software, Codice Libretto

Le command line di Java

Installazione interfaccia e software di controllo mediante PC Installing the PC communication interface and control software

PROGETTO parte di Programma Strategico

6.5 RNA Secondary Structure

Fondamenti di Java. hashcode

Test e collaudo del software Continuous Integration and Testing

UNIVERSITÀ DEGLI STUDI DI TORINO. Instructions to apply for exams ONLINE Version 01 updated on 17/11/2014

Lesson 18 (B2) Future continuous. Forma

Sezione 1 / Section 1. Elementi d identità: il marchio Elements of identity: the logo

COSMO. Screwdriving System equipped with Electronic Torque Control

Approcci agili per affrontare la sfida della complessità

Posta elettronica per gli studenti for the students

Transcript:

Test Driven Development in action Corrado Aaron Visaggio visaggio@unisannio.it, Research Centre on Software Technology - RCOST University of Sannio Benevento, Italy Corrado Aaron Visaggio 1 Agile Manifesto L Agile Manifesto (agilemanifesto.org). descrive i principi guida che orientano lo sviluppo degli Agile Methods: Individui ed iterazioni piuttosto che processi e strumenti; Software funzionante piuttosto che documentazione onnicomprensiva. Collaborazione del committente piuttosto che negoziazione del contratto. Rispondere al cambiamento piuttosto che seguire un piano. Corrado Aaron Visaggio 2

Agile Manifesto L Agile Manifesto (agilemanifesto.org). descrive i principi guida che orientano lo sviluppo degli Agile Methods: Individui ed iterazioni piuttosto che processi e strumenti; Software funzionante piuttosto che documentazione onnicomprensiva. Collaborazione del committente Scrum piuttosto che negoziazione del contratto. http://jeffsutherland.org/scrum/ Rispondere al cambiamento piuttosto che seguire un piano. Crystal http://alistair.cockburn.us/crystal/crystal.html Corrado Aaron Visaggio 3 extreme Progamming: the r-evolution XP nasce da un idea di Kent Beck [Beck, 2000]. La sua prima applicazione è stata in Daimler Chrysler, nel progetto C3, un progetto di gestione stipendi. I valori di XP: Comunicazione. Semplicità. Feedback. Coraggio. http:// www.extremeprogramming.org Corrado Aaron Visaggio 4

XP: the 12 practices Planning Game. Pianificazione delle iterazioni successive, tramite gli stand up meeting. Scrittura delle story card. Small releases. Devono essere rilasciate piccole versioni funzionanti del software. Metaphor. Il team di progetto deve avere una visione chiara e precisa degli elementi architetturali e delle relazioni che vi intercorrono. Simple design. Il progetto del sistema deve essere semplice. Corrado Aaron Visaggio 5...XP: the 12 practices... Testing. La codifica deve seguire la scrittura degli unit test. Refactoring [Fowler, 2000]. Pair programming. Collective Ownership. Chiunque può modificare qualunque porzione di codice. Continuous Integration. Integrazione dei prodotti delle singole coppie nella Code Base. 40-Hour week. Corrado Aaron Visaggio 6

...XP: the 12 practices On site customer. Il committente partecipa allo sviluppo del sistema. Coding Standards. La codifica deve seguire standard molto precisi. Corrado Aaron Visaggio 7 XP: il processo Corrado Aaron Visaggio 8

Definition (1/2) The test aspect TDD means that the tests for programming units [in Object Oriented Programming unit means a class method] drive the code writing. The programmer writes the test prior to the code to be tested. The programmer changes the code according to the results of the tests: the code rises from the tests ( results) In usual unit test the programmer writes the code as first and then (writes and) executes the tests. Corrado Aaron Visaggio 9 The driven aspect Definition (2/2) The goal of TDD is write clean code that works: TDD should avoid duplication in the code code is changed only when the test fails. TDD should drives the decisions to make about the design, including interface and code of each method. TDD is not a technique for testing, but for developing. The development aspect TDD is a practice of code development, it is not a process: it can be used in larger processes together with other practices. Tests produced during tdd is relevant part of the product s set and shouldn t be thrown away. Corrado Aaron Visaggio 10

The process of TDD start Write class interfaces Write the tests Execute the tests Write/change the code Go to the next class No Did the tests fail? Yes Corrado Aaron Visaggio 11 The Process of Testing After Coding (TAC) start Write class interfaces Write/change the code Write the tests Execute the tests Drivers+stub Go to the next class Did Yes the tests fail? No Corrado Aaron Visaggio 12

The Example The Use Case Story: to write a program that should calculate the sum and the difference of two integers and should return the results. Corrado Aaron Visaggio 13 TDD: first step Step 1. Let s write the interfaces of the class write a rough version of the methods body, too. public class MathsOperation { int result; public integer add (integer int1; integer int2) {result= int1+int2;} public integer difference (integer int1; integer int2) {result=int1-int2;} public integer getresult() {} } Corrado Aaron Visaggio 14

TDD: second & third step Step 2. Let s write the test code MathsOperation calc= new clalc(); assertequals(4; calc.add(0,4)); assertequals(4; calc.add(4,0)); assertequals(4; calc.add(2,2)); assertequals(4; calc.add(2,2)); assertequals(2*integer.max_value; calc.add(integer.max_value, Integer.MAX_VALUE)); assertequals (4; calc.add(2,2)); assertequals (0; calc.difference(2,2)); assertequals (1; calc.difference(2,3)); //now I d like to have the result of the last sum assertequals(4; calc.getresult()); Step 3. Let s execute the test code look the bar is RED: something went wrong, go to the Corrado Aaron Visaggio 15 code and change it! Corrado Aaron Visaggio 16

TDD: fourth step (1/2) Step 4. Let s improve the code on the basis of the test feedback: assertequals(2*integer.max_value; calc.add(integer.max_value, Integer.MAX_VALUE)); The mistakes is due to the absence of the controls on the maximum value; the solution is to add a control in the method like that: if ((int1== Integer.MAX_VALUE) (int2== Integer.MAX_VALUE)) then System.out.println( Please, enter number smaller than 2 31-1. ); Now, let s go on with tests; the bar is red again... Corrado Aaron Visaggio 17 TDD: fourth step (2/3) assertequals (1; calc.difference(2,3)); The mistakes is due to the absence of a controls on the inputs: the result must be an integer, so the order is important; the solution is to add a control in the method like that: if ((int1 < int2) then result= int2-int1; else int1-int2. The bar is yet RED... Corrado Aaron Visaggio 18

TDD: fourth step (3/3) assertequals(4; calc.getresult()); The mistakes suggests me that I need two variables for results: public class MathsOperation { int sumresult; int differenceresult; public integer add (integer int1; integer int2) {sumresult= int1+int2;} public integer difference (integer int1; integer int2) {differenceresult=int1-int2} public integer getsum() {return sumresult;} public integer getdifference() {return differenceresult;} } Finally the bar is GREEN everything is ok. Corrado Aaron Visaggio 19 TAC: first step First step: in TAC the phase of analysis is more accurate, the code should be written in a more precise way. public class MathsOperation { int sumresult; int differenceresult; public integer add (integer int1; integer int2) {sumresult= int1+int2;} public integer difference (integer int1; integer int2) {differenceresult=int1-int2} public integer getsumresult() {return sumresult;} public integer getdifferenceresult() {return differenceresult;} } Corrado Aaron Visaggio 20

TAC: the process After the code, the test bed should be written. The test bed will be a java class, with a main method and assertequals method. After having executed the tests, the developer should analyse all the test s results and make all the corrections together on the code. On the contrary, with tdd, the corrections were made incrementally. Corrado Aaron Visaggio 21 TAC: the test bed public class TestBed { public static void main(string[] args) { MathsOperation calc= new MathsOperation (); assertequals(4, calc.add(0,4)); assertequals(4, calc.add(4,0)); assertequals(4, calc.add(2,2)); assertequals(4, calc.add(2,2)); assertequals(2*integer.max_value, calc.add(integer.max_value, Integer.MAX_VALUE)); assertequals (4, calc.add(2,2)); assertequals (0, calc.difference(2,2)); assertequals (1, calc.difference(2,3)); // now I d like to have the result of the last sum assertequals(4, calc.getsumresult()); } public static boolean assertequals (int value1, int value2) { System.out.print("expected :" + value1 + " ; obtained: "+ value2); if (value1!= value2) { System.out.println(": Test Failed!"); return false;} else { System.out.println(": Test Succeded!"); return false; Corrado Aaron Visaggio 22 }}}

TAC: the test results expected :4 ; obtained: 4: Test Succeded! expected :4 ; obtained: 4: Test Succeded! expected :4 ; obtained: 4: Test Succeded! expected :4 ; obtained: 4: Test Succeded! expected :-2 ; obtained: -2: Test Succeded! [this is not correct, because the computer records -2 instead of 2*( 2 31-1)] expected :4 ; obtained: 4: Test Succeded! expected :0 ; obtained: 0: Test Succeded! expected :1 ; obtained: -1: Test Failed! expected :4 ; obtained: 4: Test Succeded! Corrado Aaron Visaggio 23 TAC: change the code The code is changed accordingly to the test s result. The code obtained will be the same obtained with the tdd. Corrado Aaron Visaggio 24

Test Driven Development links The home: http://www.testdriven.com/modules/news/ JUnit org: http://www.junit.org/index.htm JUnit tour: http://junit.sourceforge.net/doc/cookstour/cookstour.htm Corrado Aaron Visaggio 25 Corrado Aaron Visaggio 26