ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
JUnit Un framework per i Test
Sono utili quando vogliamo appunto testare determinate funzionalità del nostro software, in fase di progettazione, di implementazione di nuove specifiche, di manutenzione.
Evitiamo di perdere tempo a correggere bug stupidi.Perché fare i test
Struttura di Junit
I metodi setUp(), runTest() e tearDown() dispongono in verità di un’implementazione di default consistente in un corpo
I metodi setUp() e tearDown() sono invocati rispettivamente giusto prima e subito dopo l’invocazione di un metodo di testAlcune Precisazioni
public  class Calcolatrice {public  int somma(int a , int b ){returna+b;}public  intsottrai(int a , int b){return a-b;}publicintmoltiplica(int a , int b){return a*b;}public int dividi ( int a , int b){return a/b;}Ma passiamo ai fatti! - Un Esempio

More Related Content

Viewers also liked (6)

Edital concurso Ministério da Cultura 2012Edital concurso Ministério da Cultura 2012
Edital concurso Ministério da Cultura 2012
Concurso Virtual
Ìý
Boletín de empleo 60 Albacete de mica consultores_ofertas de trabajo de AlbaceteBoletín de empleo 60 Albacete de mica consultores_ofertas de trabajo de Albacete
Boletín de empleo 60 Albacete de mica consultores_ofertas de trabajo de Albacete
MICA CONSULTORES
Ìý
Visit of indian IT delegation to Estonia
Visit of indian IT delegation to EstoniaVisit of indian IT delegation to Estonia
Visit of indian IT delegation to Estonia
Indian Society Estonia
Ìý
Edital concurso Ministério da Cultura 2012Edital concurso Ministério da Cultura 2012
Edital concurso Ministério da Cultura 2012
Concurso Virtual
Ìý
Boletín de empleo 60 Albacete de mica consultores_ofertas de trabajo de AlbaceteBoletín de empleo 60 Albacete de mica consultores_ofertas de trabajo de Albacete
Boletín de empleo 60 Albacete de mica consultores_ofertas de trabajo de Albacete
MICA CONSULTORES
Ìý
Visit of indian IT delegation to Estonia
Visit of indian IT delegation to EstoniaVisit of indian IT delegation to Estonia
Visit of indian IT delegation to Estonia
Indian Society Estonia
Ìý

Similar to Junit tutorial (20)

Introduzione al Test Driven Development
Introduzione al Test Driven DevelopmentIntroduzione al Test Driven Development
Introduzione al Test Driven Development
Ennio Masi
Ìý
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
Ìý
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
Daniel Londero
Ìý
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
sazilla
Ìý
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
sazilla
Ìý
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
Alessandro Alpi
Ìý
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql Server
Alessandro Alpi
Ìý
CONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERCONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVER
DotNetCampus
Ìý
Googletest, tdd e mock
Googletest, tdd e mockGoogletest, tdd e mock
Googletest, tdd e mock
yuroller
Ìý
Tdd.Every.Where.21012012
Tdd.Every.Where.21012012Tdd.Every.Where.21012012
Tdd.Every.Where.21012012
LEGALDESK
Ìý
Workshop Test Drive Development
Workshop Test Drive DevelopmentWorkshop Test Drive Development
Workshop Test Drive Development
Commit University
Ìý
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
Ìý
Software Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSoftware Testing & Test Driven Development
Software Testing & Test Driven Development
Sergio Santoro
Ìý
iContract
iContractiContract
iContract
guest891383
Ìý
Javaday 2006: Java 5
Javaday 2006: Java 5Javaday 2006: Java 5
Javaday 2006: Java 5
Matteo Baccan
Ìý
Software Testing e TDD
Software Testing e TDDSoftware Testing e TDD
Software Testing e TDD
Domenico Briganti
Ìý
Unit test
Unit testUnit test
Unit test
Roberto Cappelletti
Ìý
Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)
Carmelantonio Zolfo
Ìý
Introduzione al Test Driven Development
Introduzione al Test Driven DevelopmentIntroduzione al Test Driven Development
Introduzione al Test Driven Development
Ennio Masi
Ìý
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
Ìý
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
Daniel Londero
Ìý
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
sazilla
Ìý
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
sazilla
Ìý
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
Alessandro Alpi
Ìý
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql Server
Alessandro Alpi
Ìý
CONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERCONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVER
DotNetCampus
Ìý
Googletest, tdd e mock
Googletest, tdd e mockGoogletest, tdd e mock
Googletest, tdd e mock
yuroller
Ìý
Tdd.Every.Where.21012012
Tdd.Every.Where.21012012Tdd.Every.Where.21012012
Tdd.Every.Where.21012012
LEGALDESK
Ìý
Workshop Test Drive Development
Workshop Test Drive DevelopmentWorkshop Test Drive Development
Workshop Test Drive Development
Commit University
Ìý
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
Ìý
Software Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSoftware Testing & Test Driven Development
Software Testing & Test Driven Development
Sergio Santoro
Ìý
Javaday 2006: Java 5
Javaday 2006: Java 5Javaday 2006: Java 5
Javaday 2006: Java 5
Matteo Baccan
Ìý
Software Testing e TDD
Software Testing e TDDSoftware Testing e TDD
Software Testing e TDD
Domenico Briganti
Ìý
Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)
Carmelantonio Zolfo
Ìý

Junit tutorial

  • 1. JUnit Un framework per i Test
  • 2. Sono utili quando vogliamo appunto testare determinate funzionalità del nostro software, in fase di progettazione, di implementazione di nuove specifiche, di manutenzione.
  • 3. Evitiamo di perdere tempo a correggere bug stupidi.Perché fare i test
  • 5. I metodi setUp(), runTest() e tearDown() dispongono in verità di un’implementazione di default consistente in un corpo
  • 6. I metodi setUp() e tearDown() sono invocati rispettivamente giusto prima e subito dopo l’invocazione di un metodo di testAlcune Precisazioni
  • 7. public class Calcolatrice {public int somma(int a , int b ){returna+b;}public intsottrai(int a , int b){return a-b;}publicintmoltiplica(int a , int b){return a*b;}public int dividi ( int a , int b){return a/b;}Ma passiamo ai fatti! - Un Esempio
  • 8. public class TestSomma extends TestCase {private Calcolatrice calc ;public TestSomma() {this.calc = new Calcolatrice();}public voidtestAdd() { int num1 = 3; int num2 = 2; inttotal = 5; int sum = 0; sum = this.calc.somma(num1, num2);assertEquals(sum, total); } Facciamo Un TestCase/** * Preparare l'ambiente per l'esecuzione del test */@Overrideprotected void setUp() throws Exception {super.setUp();}/** * Buttare via tutti gli ogetti che non servono più per */@Overrideprotected void tearDown() throws Exception {super.tearDown();}}
  • 9. L’ambiente maven ingloba junit e permette di eseguire tutti i test direttamente al momento della compilazione di un progetto maven .
  • 11. Se invece vuoi compilare senza che vengano eseguiti i test: mvncleaninstall –DSkipTests=trueJUnit con maven