SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
TESTING




         Angelo Lupo
angelo.lupo@manydesigns.com
Introduzione
      Perchè non tutti i programmatori
         utilizzano i test automatici

– Mancanza di tempo
– Troppo bravo per introdurre errori
– Se cambiano i requisiti del software
  devono anche cambiare i test
– Non ha mai provato test automatizzati
– Scarsa cultura aziendale sui vantaggi del
  testing automatizzato
Testing manuale Vs testing
automatico
             Test manuali

– Lunghi da eseguire
– Facile inserire errori
– Difficilmente ripetibili
– Non si riesce a tenere traccia   dei test
  fatti
– Ogni programmatore segue una pro-
  pria “politica”
Testing manuale Vs testing
   automatico
               Test automatici
–Aumentano la produttività
–Favorisco il refactoring ed il merging
–Danno garanzie di qualità
–Con strumenti di code coverage di
supporto al testing è possibile stimare il
grado di robustezza dell'applicazione
testata
Tipi di test automatico
    Testing funzionale
●

     – Verifica le funzionalità del software
     – Validazione delle specifiche
     – Controlla che il software esegua quanto è stato
     richiesto in fase di progettazione

    Regression Test
●

     – Sono i test che verificano il corretto funzionamen-
       to del programma dopo aver apportato apportato
       nuove modifiche (Es. Cambio API, Database,etc.)

    Testing prestazione
●

     – Misura le prestazioni del software
Panoramica strumenti testing


  Junit
●

● testNg

● Selenium

● Fitnesse

● Cobertura

● HttpUnit, JpdfUnit,ecc
Esempio Junit
public class HelloWord {

    public String getHelloWord() {
      return quot;Hello, worldquot;;
    }

    public static void main() {
      Hello h = new Hello();
      System.out.println(h.greet());
    }
}

public class TestHelloWord extends TestCase {

       HelloHord hello = null;

       protected void setUp() {
              HelloWord hello = new HelloWord();
       }

       public void testHelloWord() {
              assertEquals(hello.getHelloWord, quot;Hello, worldquot;);
       }
       protected void tearDown() {
               hello = null;
       }
}
Esempio HttpUnit
 ServletUnitClient client = sr.newClient();
  String url = quot;http://127.0.0.1/Indexquot;;
  System.out.println(url);
  WebResponse resp = client.getResponse(url);
  assertEquals(quot;Codice risposta.quot;,
       HttpServletResponse.SC_OK, resp.getResponseCode());

  WebLink link = resp.getLinkWith(quot;Reportquot;);
  assertNotNull(quot;Reportquot;, link);
  resp = link.click();
  assertEquals(quot;Codice risposta.quot;,
       HttpServletResponse.SC_OK, resp.getResponseCode());
Esempio selenium
    import com.thoughtworks.selenium.*;
●

    public class AndTest extends TestCase {
●

        private Selenium sel;
●

        public void setUp() {
●

            sel = new DefaultSelenium(quot;localhostquot;,
●

                   4444, quot;*firefoxquot;, quot;http://www.google.comquot;);
●

           sel.start;
        }
●

●

        public void testGoogle() {
●

            sel.open(quot;http://www.google.com/webhpquot;);
●

            sel.type(quot;qquot;, quot;hello worldquot;);
●

            sel.click(quot;btnGquot;);
●

            sel.waitForPageToLoad(quot;5000quot;);
●

            assertEquals(quot;hello world - Cerca con Googlequot;,
●

    sel.getTitle());
        }
●

●

        public void tearDown() {
●

          sel.stop();
●

        }
●

    }
●
Organizzazione dei test
    Sezione di inizializzazione del test
●

     – Creazione delle connessioni
     – Creazione del database
     – Creazioni file
     – Importante fare in modo che il test parta sempre
       da uno stato not.

    Test vero e proprio
●




    Sezione di chiusura del test
●

     – Chiusura delle connessioni
     – Cancellazione del database e dei file
Organizzazione dei test

     MockObject
 ●

         Per testare una singola classe è necessario rendere
     –
         tale classe indipendente dalle altri classi. La classe va
         testata “da sola”. Un mockObject è appunto un
         oggetto che rispetta la stessa interfaccia dell'oggetto
         che “sostituisce” e permette di testare una classe in
         isolamento.
         Grazie ai mockObject non è possibile solamente
     –
         testare l'output di un metodo ma anche l'interazione
         delle classi con altre classi.
         Esistono dei framework per creare mockObject.
     –
Esempio Cobertura
Problematiche

    Testare un applicazione web può rivelarsi un
●

    impresa ardua :

        Incompatibilità dei browser
    –
        Web 2.0
    –



    Creare ambiente di test spesso è oneroso in termini
●

    di tempo. La creazione di un database di test puo'
    richiedere diversi minuti

Contenu connexe

Similaire à Presentazione Testing automatizzato

Java Unit Testing - Introduction
Java Unit Testing - IntroductionJava Unit Testing - Introduction
Java Unit Testing - Introductionfgianneschi
 
Java Unit Testing - In container and database testing
Java Unit Testing - In container and database testingJava Unit Testing - In container and database testing
Java Unit Testing - In container and database testingfgianneschi
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Developmentsazilla
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Developmentsazilla
 
CONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERCONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERDotNetCampus
 
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerAlessandro Alpi
 
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...Alessandro Alpi
 
TDD in WordPress
TDD in WordPressTDD in WordPress
TDD in WordPresslucatume
 
Dominare il codice legacy
Dominare il codice legacyDominare il codice legacy
Dominare il codice legacyTommaso Torti
 
PASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous IntegrationPASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous IntegrationAlessandro Alpi
 
Software Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSoftware Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSergio Santoro
 
Selenium e testing web - di Alessio Benedetti
Selenium e testing web - di Alessio BenedettiSelenium e testing web - di Alessio Benedetti
Selenium e testing web - di Alessio BenedettiGiuneco S.r.l
 
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...Davide Cerbo
 
Tech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non soloTech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non soloCodemotion
 

Similaire à Presentazione Testing automatizzato (20)

Java Unit Testing - Introduction
Java Unit Testing - IntroductionJava Unit Testing - Introduction
Java Unit Testing - Introduction
 
Java Unit Testing - In container and database testing
Java Unit Testing - In container and database testingJava Unit Testing - In container and database testing
Java Unit Testing - In container and database testing
 
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
CONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERCONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVER
 
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql Server
 
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
 
Il testing con zend framework
Il testing con zend frameworkIl testing con zend framework
Il testing con zend framework
 
Il testing con zend framework
Il testing con zend frameworkIl testing con zend framework
Il testing con zend framework
 
Applicazioni native in java
Applicazioni native in javaApplicazioni native in java
Applicazioni native in java
 
TDD in WordPress
TDD in WordPressTDD in WordPress
TDD in WordPress
 
Dominare il codice legacy
Dominare il codice legacyDominare il codice legacy
Dominare il codice legacy
 
PASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous IntegrationPASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous Integration
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Software Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSoftware Testing & Test Driven Development
Software Testing & Test Driven Development
 
Selenium e testing web - di Alessio Benedetti
Selenium e testing web - di Alessio BenedettiSelenium e testing web - di Alessio Benedetti
Selenium e testing web - di Alessio Benedetti
 
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
 
Tech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non soloTech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non solo
 
Software Testing e TDD
Software Testing e TDDSoftware Testing e TDD
Software Testing e TDD
 

Presentazione Testing automatizzato

  • 1. TESTING Angelo Lupo angelo.lupo@manydesigns.com
  • 2. Introduzione Perchè non tutti i programmatori utilizzano i test automatici – Mancanza di tempo – Troppo bravo per introdurre errori – Se cambiano i requisiti del software devono anche cambiare i test – Non ha mai provato test automatizzati – Scarsa cultura aziendale sui vantaggi del testing automatizzato
  • 3. Testing manuale Vs testing automatico Test manuali – Lunghi da eseguire – Facile inserire errori – Difficilmente ripetibili – Non si riesce a tenere traccia dei test fatti – Ogni programmatore segue una pro- pria “politica”
  • 4. Testing manuale Vs testing automatico Test automatici –Aumentano la produttività –Favorisco il refactoring ed il merging –Danno garanzie di qualità –Con strumenti di code coverage di supporto al testing è possibile stimare il grado di robustezza dell'applicazione testata
  • 5. Tipi di test automatico Testing funzionale ● – Verifica le funzionalità del software – Validazione delle specifiche – Controlla che il software esegua quanto è stato richiesto in fase di progettazione Regression Test ● – Sono i test che verificano il corretto funzionamen- to del programma dopo aver apportato apportato nuove modifiche (Es. Cambio API, Database,etc.) Testing prestazione ● – Misura le prestazioni del software
  • 6. Panoramica strumenti testing Junit ● ● testNg ● Selenium ● Fitnesse ● Cobertura ● HttpUnit, JpdfUnit,ecc
  • 7. Esempio Junit public class HelloWord { public String getHelloWord() { return quot;Hello, worldquot;; } public static void main() { Hello h = new Hello(); System.out.println(h.greet()); } } public class TestHelloWord extends TestCase { HelloHord hello = null; protected void setUp() { HelloWord hello = new HelloWord(); } public void testHelloWord() { assertEquals(hello.getHelloWord, quot;Hello, worldquot;); } protected void tearDown() { hello = null; } }
  • 8. Esempio HttpUnit ServletUnitClient client = sr.newClient(); String url = quot;http://127.0.0.1/Indexquot;; System.out.println(url); WebResponse resp = client.getResponse(url); assertEquals(quot;Codice risposta.quot;, HttpServletResponse.SC_OK, resp.getResponseCode()); WebLink link = resp.getLinkWith(quot;Reportquot;); assertNotNull(quot;Reportquot;, link); resp = link.click(); assertEquals(quot;Codice risposta.quot;, HttpServletResponse.SC_OK, resp.getResponseCode());
  • 9. Esempio selenium import com.thoughtworks.selenium.*; ● public class AndTest extends TestCase { ● private Selenium sel; ● public void setUp() { ● sel = new DefaultSelenium(quot;localhostquot;, ● 4444, quot;*firefoxquot;, quot;http://www.google.comquot;); ● sel.start; } ● ● public void testGoogle() { ● sel.open(quot;http://www.google.com/webhpquot;); ● sel.type(quot;qquot;, quot;hello worldquot;); ● sel.click(quot;btnGquot;); ● sel.waitForPageToLoad(quot;5000quot;); ● assertEquals(quot;hello world - Cerca con Googlequot;, ● sel.getTitle()); } ● ● public void tearDown() { ● sel.stop(); ● } ● } ●
  • 10. Organizzazione dei test Sezione di inizializzazione del test ● – Creazione delle connessioni – Creazione del database – Creazioni file – Importante fare in modo che il test parta sempre da uno stato not. Test vero e proprio ● Sezione di chiusura del test ● – Chiusura delle connessioni – Cancellazione del database e dei file
  • 11. Organizzazione dei test MockObject ● Per testare una singola classe è necessario rendere – tale classe indipendente dalle altri classi. La classe va testata “da sola”. Un mockObject è appunto un oggetto che rispetta la stessa interfaccia dell'oggetto che “sostituisce” e permette di testare una classe in isolamento. Grazie ai mockObject non è possibile solamente – testare l'output di un metodo ma anche l'interazione delle classi con altre classi. Esistono dei framework per creare mockObject. –
  • 13.
  • 14. Problematiche Testare un applicazione web può rivelarsi un ● impresa ardua : Incompatibilità dei browser – Web 2.0 – Creare ambiente di test spesso è oneroso in termini ● di tempo. La creazione di un database di test puo' richiedere diversi minuti