Submit Search
Upload
2011 nri-pratiques tests-avancees
•
Download as PPTX, PDF
•
1 like
•
1,053 views
Nathaniel Richand
Follow
Le support de la présentation donné en mars 2011 au ScrumDay
Read less
Read more
Technology
Report
Share
Report
Share
1 of 44
Download now
Recommended
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196
Mahmoud Samir Fayed
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
code for quiz in my sql
code for quiz in my sql
JOYITAKUNDU1
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
Mattbrenner
Mattbrenner
Droidcon Berlin
Advanced Java Practical File
Advanced Java Practical File
Soumya Behera
java experiments and programs
java experiments and programs
Karuppaiyaa123
Ip project visual mobile
Ip project visual mobile
Kendriya vidyalaya no.1 cantt shahjahanpur
Recommended
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196
Mahmoud Samir Fayed
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
code for quiz in my sql
code for quiz in my sql
JOYITAKUNDU1
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
Mattbrenner
Mattbrenner
Droidcon Berlin
Advanced Java Practical File
Advanced Java Practical File
Soumya Behera
java experiments and programs
java experiments and programs
Karuppaiyaa123
Ip project visual mobile
Ip project visual mobile
Kendriya vidyalaya no.1 cantt shahjahanpur
The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202
Mahmoud Samir Fayed
The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88
Mahmoud Samir Fayed
The Ring programming language version 1.4 book - Part 17 of 30
The Ring programming language version 1.4 book - Part 17 of 30
Mahmoud Samir Fayed
Spring data access
Spring data access
명철 강
The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30
Mahmoud Samir Fayed
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184
Mahmoud Samir Fayed
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
Writing Good Tests
Writing Good Tests
Matteo Baglini
662305 11
662305 11
Nitigan Nakjuatong
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
Container adapters
Container adapters
mohamed sikander
Scala meetup
Scala meetup
扬 明
MaintainStaffTable
MaintainStaffTable
William Rutherford
Design pattern - part 3
Design pattern - part 3
Jieyi Wu
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
재춘 노
IP project for class 12 cbse
IP project for class 12 cbse
siddharthjha34
Design pattern part 2 - structural pattern
Design pattern part 2 - structural pattern
Jieyi Wu
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
Wwe Management System
Wwe Management System
NeerajMudgal1
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트
기룡 남
JavaScript Refactoring
JavaScript Refactoring
Krzysztof Szafranek
Chapter 2
Chapter 2
application developer
More Related Content
What's hot
The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202
Mahmoud Samir Fayed
The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88
Mahmoud Samir Fayed
The Ring programming language version 1.4 book - Part 17 of 30
The Ring programming language version 1.4 book - Part 17 of 30
Mahmoud Samir Fayed
Spring data access
Spring data access
명철 강
The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30
Mahmoud Samir Fayed
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184
Mahmoud Samir Fayed
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
Writing Good Tests
Writing Good Tests
Matteo Baglini
662305 11
662305 11
Nitigan Nakjuatong
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
Container adapters
Container adapters
mohamed sikander
Scala meetup
Scala meetup
扬 明
MaintainStaffTable
MaintainStaffTable
William Rutherford
Design pattern - part 3
Design pattern - part 3
Jieyi Wu
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
재춘 노
IP project for class 12 cbse
IP project for class 12 cbse
siddharthjha34
Design pattern part 2 - structural pattern
Design pattern part 2 - structural pattern
Jieyi Wu
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
Wwe Management System
Wwe Management System
NeerajMudgal1
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트
기룡 남
What's hot
(20)
The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.3 book - Part 50 of 88
The Ring programming language version 1.4 book - Part 17 of 30
The Ring programming language version 1.4 book - Part 17 of 30
Spring data access
Spring data access
The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.4 book - Part 18 of 30
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.3 book - Part 77 of 184
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
Writing Good Tests
Writing Good Tests
662305 11
662305 11
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Container adapters
Container adapters
Scala meetup
Scala meetup
MaintainStaffTable
MaintainStaffTable
Design pattern - part 3
Design pattern - part 3
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
IP project for class 12 cbse
IP project for class 12 cbse
Design pattern part 2 - structural pattern
Design pattern part 2 - structural pattern
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
Wwe Management System
Wwe Management System
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트
Similar to 2011 nri-pratiques tests-avancees
JavaScript Refactoring
JavaScript Refactoring
Krzysztof Szafranek
Chapter 2
Chapter 2
application developer
Drools BeJUG 2010
Drools BeJUG 2010
Geoffrey De Smet
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
Working effectively with legacy code
Working effectively with legacy code
ShriKant Vashishtha
Kickstarting SItes With a Custom Package
Kickstarting SItes With a Custom Package
Jeff Segars
Domain Driven Design 101
Domain Driven Design 101
Richard Dingwall
Qt Workshop
Qt Workshop
Johan Thelin
Functional C++
Functional C++
Kevlin Henney
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
David Gómez García
Java and xml
Java and xml
info_zybotech
Windows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best Practices
Sriram Krishnan
Intro
Intro
bspremo
Presentacion clean code
Presentacion clean code
IBM
applet.docx
applet.docx
nofakeNews
Move Accumulation To Collecting Parameter
Move Accumulation To Collecting Parameter
melbournepatterns
C#, What Is Next?
C#, What Is Next?
Pieter Joost van de Sande
All I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
Akira Maruoka
Similar to 2011 nri-pratiques tests-avancees
(20)
JavaScript Refactoring
JavaScript Refactoring
Chapter 2
Chapter 2
Drools BeJUG 2010
Drools BeJUG 2010
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
Whats new in_csharp4
Whats new in_csharp4
Working effectively with legacy code
Working effectively with legacy code
Kickstarting SItes With a Custom Package
Kickstarting SItes With a Custom Package
Domain Driven Design 101
Domain Driven Design 101
Qt Workshop
Qt Workshop
Functional C++
Functional C++
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Java and xml
Java and xml
Windows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best Practices
Intro
Intro
Presentacion clean code
Presentacion clean code
applet.docx
applet.docx
Move Accumulation To Collecting Parameter
Move Accumulation To Collecting Parameter
C#, What Is Next?
C#, What Is Next?
All I know about rsc.io/c2go
All I know about rsc.io/c2go
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
More from Nathaniel Richand
Devenir une entreprise resiliente avec la permagilité
Devenir une entreprise resiliente avec la permagilité
Nathaniel Richand
Proposition séminaire agile
Proposition séminaire agile
Nathaniel Richand
Permagilite
Permagilite
Nathaniel Richand
2017 brownbaglunch Kanban
2017 brownbaglunch Kanban
Nathaniel Richand
Présentation Dashing
Présentation Dashing
Nathaniel Richand
Devenir une organisation apprenante dans l'IT en 2014
Devenir une organisation apprenante dans l'IT en 2014
Nathaniel Richand
2013 brownbaglunch - lean startup
2013 brownbaglunch - lean startup
Nathaniel Richand
Brownbaglunch Rétrospective
Brownbaglunch Rétrospective
Nathaniel Richand
Brown baglunch xebia
Brown baglunch xebia
Nathaniel Richand
Lean canvas brochure
Lean canvas brochure
Nathaniel Richand
Continuous integration
Continuous integration
Nathaniel Richand
Josiane ScrumDay 2012
Josiane ScrumDay 2012
Nathaniel Richand
2011 XKE - Kanban in action
2011 XKE - Kanban in action
Nathaniel Richand
2010 agile conférence - Comment vendre les tests automatisés
2010 agile conférence - Comment vendre les tests automatisés
Nathaniel Richand
XKE - La communication
XKE - La communication
Nathaniel Richand
Presentation Zen
Presentation Zen
Nathaniel Richand
Presentation Spring
Presentation Spring
Nathaniel Richand
Tests Logiciel
Tests Logiciel
Nathaniel Richand
Presentation Spring, Spring MVC
Presentation Spring, Spring MVC
Nathaniel Richand
More from Nathaniel Richand
(19)
Devenir une entreprise resiliente avec la permagilité
Devenir une entreprise resiliente avec la permagilité
Proposition séminaire agile
Proposition séminaire agile
Permagilite
Permagilite
2017 brownbaglunch Kanban
2017 brownbaglunch Kanban
Présentation Dashing
Présentation Dashing
Devenir une organisation apprenante dans l'IT en 2014
Devenir une organisation apprenante dans l'IT en 2014
2013 brownbaglunch - lean startup
2013 brownbaglunch - lean startup
Brownbaglunch Rétrospective
Brownbaglunch Rétrospective
Brown baglunch xebia
Brown baglunch xebia
Lean canvas brochure
Lean canvas brochure
Continuous integration
Continuous integration
Josiane ScrumDay 2012
Josiane ScrumDay 2012
2011 XKE - Kanban in action
2011 XKE - Kanban in action
2010 agile conférence - Comment vendre les tests automatisés
2010 agile conférence - Comment vendre les tests automatisés
XKE - La communication
XKE - La communication
Presentation Zen
Presentation Zen
Presentation Spring
Presentation Spring
Tests Logiciel
Tests Logiciel
Presentation Spring, Spring MVC
Presentation Spring, Spring MVC
Recently uploaded
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Memoori
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Sinan KOZAK
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
2toLead Limited
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
shyamraj55
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Mark Billinghurst
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Scott Keck-Warren
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
carlostorres15106
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Softradix Technologies
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
Allon Mureinik
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Deakin University
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Hyundai Motor Group
The transition to renewables in India.pdf
The transition to renewables in India.pdf
Competition Advisory Services (India) LLP
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Puma Security, LLC
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
naman860154
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
AndikSusilo4
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Delhi Call girls
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Patryk Bandurski
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Delhi Call girls
Slack Application Development 101 Slides
Slack Application Development 101 Slides
praypatel2
Recently uploaded
(20)
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
The transition to renewables in India.pdf
The transition to renewables in India.pdf
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Slack Application Development 101 Slides
Slack Application Development 101 Slides
2011 nri-pratiques tests-avancees
1.
Pratiques avancées de
testsNathaniel Richand Scrumday France 2011
2.
Merci aux sponsors
du Scrumday ! Sponsors Platinum Sponsors Gold Parrainage :
3.
4.
Restons pragmatique !
Doit-on : Tester les messages d’exceptions ? Tester les messages de logs ? Contexte
5.
TDD a beaucoup
aidé
6.
Certains tests vieillissent
mal
7.
Tests illisibleset fragiles
Exemple
8.
Constat : TDD
peut : devenir un frein, diminuer le rythme Augmenter la rigidité du code
9.
Améliorer la lisibilité
10.
Tip1 : le
nom donnel’intention testChoose1() testChoose2() whenSelectNullIItem_ShouldThrowAnException() whenSelectTwoItems_ShouldReturnTheSum()
11.
Tip2 : Ne
pas masquer les informationsutiles @DataSet publicclassBrokerDAOTestextendsUnitilsTestNG { @Test publicvoidtestGetNameByClauseInId() { BrokerDASbdao = newBrokerDAO(); JpaUnitils.injectEntityManagerInto(bdao); List<String> brokers = bdao.getNameByClauseInId("in (1)"); assertEquals(brokers.size(), 1); assertEquals(brokers.get(0), "Kerviel"); } } WTF?
12.
Tip3 : Masquer
tout ce qui est inutile Setup & Teardown Fixture Creation method Creation Builder Static import
13.
@Test publicvoidgenerateNomDeFichierNacXMLTest(){ //Given
NacCreatorBOnacCreator = newNacCreatorBO(); //when String nomFichier= nacCreator.generateNomDeFichierNacXML (creerDateBlanchie(2010, 01, 02), "123456", creerDateBlanchie(2010, 03, 04), 10); //then assertThat(nomFichier).isEqualTo ("NAC_R_123456RE_020110_10_040310000000.xml"); }
14.
NacCreatorBOnacCreator; @Before publicvoidinit(){
nacCreator= newNacCreatorBO(); } @Test publicvoidgenerateNomDeFichierNacXMLTest(){ //when String nomFichier = nacCreator.generateNomDeFichierNacXML (creerDateBlanchie(2010, 01, 02), "123456", creerDateBlanchie(2010, 03, 04), 10); //then assertThat(nomFichier).isEqualTo ("NAC_R_123456RE_020110_10_040310000000.xml"); }
15.
@Test publicvoidtestParserIntraday(){
File file = new File("src/test/resources/fr/haramis/service/commons/util/Planning_Options.xls"); List<IntradaySchedule> listIntradays = null; InputStreamstream = null; try{ stream= newFileInputStream(file.getAbsolutePath()); } catch(FileNotFoundException e) { stream= null; } if(stream != null){ try{ listIntradays= IntradayParser.parseExcelIntraday(stream, "DIRECT-T01"); } catch(HermesException e) { e.printStackTrace(); logger.error(e); Assert.fail(); } logger.info(" ListIntradaysSize() " +listIntradays.size()); Assert.assertEquals(8400, listIntradays.size()); for(IntradayScheduleintradaySchedule : listIntradays) { Assert.assertEquals(24, intradaySchedule.getIntraday().getIntradaySchedules().size()); } } }
16.
@Test publicvoidtestParserIntraday_OK() throws
Exception{ //Given InputStreamstream = getStreamFromFile("Planning_Options.xls"); //When List<IntradaySchedule> listIntradays = IntradayParser.parseExcelIntraday(stream, "DIRECT-T01"); //Then assertEquals(8400, listIntradays.size()); for(IntradayScheduleintradaySchedule : listIntradays) { assertEquals(24, intradaySchedule.getIntraday() .getIntradaySchedules().size()); } }
17.
//Given Map<Date, BigDecimal>
charges = newHashMap<Date, BigDecimal>(); charges.put(dateDebut_13_03_2010, newBigDecimal(QUANTITY_1000)); charges.put(addDaysToDate(dateDebut_13_03_2010, 1), newBigDecimal(QUANTITY_3000));
18.
//Given Map<Date, BigDecimal>
charges = newMapCharges<Date>() .with(dateDebut_13_03_2010, QUANTITY_1000) .and(addDaysToDate(dateDebut_13_03_2010, 1) QUANTITY_3000) .build();
19.
/** *
Builder pour créer plus facilement des Map<Date, BigDecimal> ou des Map<String, BigDecimal> */ privateclassMapCharges<T> { privateMap<T, BigDecimal> cdcMap = newHashMap<T, BigDecimal>(); publicMapCharges<T> with(T dateDebut, intquantity){ cdcMap.put(dateDebut, newBigDecimal(quantity)); returnthis; } publicMapCharges<T> and(T dateDebut, intquantity){ returnwith(dateDebut, quantity); } publicMap<T, BigDecimal> build(){ returncdcMap; } }
20.
Tip4 : try/catch
fail() @Test publicvoidtestFindByStatutAndDate() { OrdreSpotDASdao = newOrdreSpotDAO(); try{ assertEquals(dao.findByDate("01/07/2008", "OK").size(), 2); assertEquals(dao.findByDate("01/07/2008", "KO").size(), 1); } catch (HaramisExceptione) { e.printStackTrace(); Assert.fail(); } }
21.
@Test publicvoidtestFindByStatutAndDate() throwsHaramisException{
OrdreSpotDASdao = newOrdreSpotDAO(); assertEquals(dao.findByDate("01/07/2008", "OK").size(), 2); assertEquals(dao.findByDate("01/07/2008", "KO").size(), 1); }
22.
Tip4 (bis) :
if/else fail() if (sd.getTimeRef() == 0) { assertEquals(sd.getPrice(), "301"); } else{ fail("pas normal"); }
23.
assertThat(sd.getTimeRef()).isEqualTo(0); assertEquals(sd.getPrice(), "301");
GuardAssert
24.
Tip5 : Simili
de toString() dans les assert assertEquals("Compagniedifferente : "+result.getId()+" / "+ result.getName() +" / "+ result.getLocation() , result, expectedCompany); assertThat(result).isEqualTo(expectedCompany);
25.
Tip6 : Magic
number, magic null //Given Site siteNord = createSite(NORD, 10); Site siteSud = createSite(SUD, 12); //When intaffectations = dao.selectAffectationsNord(siteNord, siteSud, null); //Then assertThat(affectations).isEqualTo(10);
26.
//Given Site siteNord
= createSite(NORD, AFFECTATION_NORD); Site siteSud = createSite(SUD, AFFECTATION_SUD); //When intaffectations = dao.selectAffectationsNord(siteNord, siteSud, SITE_NULL); //Then assertThat(affectations).isEqualTo(AFFECTATION_NORD);
27.
Tip7 : Garder
la même structure @Test publicvoidcalculTotalTest(){ //Given double[] volumes = {10.24556, 21, 43}; //When double total = PositionUtils.calculTotal(UNITE_TEMPS_HORAIRE, volumes); //Then assertThat(total).isEqualTo(74.24556); }
28.
@Test publicvoidcalculerDateTest(){ //Given
Date date = HaramisDateUtils.creerDateBlanchie(2010, 5, 19); //When String[] datesFormatees = PositionUtils.calculerDates(date, 1, UNITE_TEMPS_HORAIRE, ELECTRICTY); //Then assertThat(datesFormatees).hasSize(2); assertThat(datesFormatees[0]).isEqualTo("19/05/2010 01:00"); assertThat(datesFormatees[1]).isEqualTo("19/05/2010 02:00"); }
29.
Tip8 : Faire
de belles assertions Ne surtout pas faire : assertFalse(toto == null); assertTrue(list.size() == 0); assertEquals(result, null);
30.
File emptyFile =
writeFile("emptyFile", ""); assertThat(emptyFile).hasSize(0); List<String> names = Arrays.asList("Bob", ”Vince", ”Nat"); assertThat(names) .hasSize(3) .contains("Vince") .doesNotHaveDuplicates(); String nullString = null; assertThat(nullString).isNull(); http://docs.codehaus.org/display/FEST/Fluent+Assertions+Module
31.
for (Companycie :
companies) { Assert.assertFalse(cie.getStatus() .equalsIgnoreCase(ConstantsUtils.SIMPLE_STATUS_ANNULE) , "Cie " + cie.getId()); } assertThat(companies) .onProperty("status") .containsOnly(SIMPLE_STATUS_VALIDE);
32.
Tip9 : Utiliser
Spock def"I plus I should equal II"() { given:def calculator = newRomanCalculator()when: def result = calculator.add("I", "I") then: result == "II" } http://code.google.com/p/spock/
33.
def"The lowestnumbershould go
at the end"() { setup: defresult = calculator.add(a, b)expect:result == sum where: a | b | sum "X" | "I" | "XI" "I" | "X" | "XI" "XX" | "I" | "XXI" "XX" | "II"| "XXII" "II" | "XX"| "XXII" } http://www.wakaleo.com/blog/303-an-introduction-to-spock
34.
Faire des tests
plus robustes
35.
Tip1 : Pas
de duplication Cf. Tip 3 : Masquer tout ce qui est inutile Creation fixture Creation builder Test Helper Custom assertions
36.
Tip2 : Tester
un comportementà un seulendroit publicString formatResultToCSV(List<Object[]> positionsResultats) throwsParseException; privatestatic String[] calculerDeuxDates(Object[] ligne) throwsParseException; publicstatic String[] obtenirVolumes(Object[] ligne);
37.
PublicString formatResultToCSV(List<Object[]> positionsResultats)
throwsParseException { StringBuildersb = newStringBuilder(); for(Object[] ligne : positionsResultats) { String[] twoDates = calculerDeuxDates(ligne); String[] newLine = new String[ligne.length -1]; newLine[0] = twoDates[0]; newLine[1] = twoDates[1]; String[] volumes = PositionUtils.obtenirVolumes(ligne); System.arraycopy(volumes, 0, newLine, 2, volumes.length); for(String elementLigne : newLine) { sb.append(elementLigne+"|"); } } returnsb.toString(); }
38.
Tip3 : Eviter
la réflexion @Test publicvoid testReglesValidationHRM_118_KO() throws Exception { PortfolioManagerBOportfolioManagerBO = newPortfolioManagerBO(); Method reglesValidationHRM118 = null; PortfolioFormportfolioForm = newPortfolioForm(); portfolioManagerBO.setPortfolioForm(portfolioForm); reglesValidationHRM118 = ReflectHelper.getPrivateMethod(portfolioManagerBO, "reglesValidationHRM118"); reglesValidationHRM118.setAccessible(true); reglesValidationHRM118.invoke(portfolioManagerBO); assertFalse(portfolioForm.isMessageAVisible()); assertFalse(portfolioForm.isPopupVisible()); }
39.
@Test publicvoid testReglesValidationHRM_118_OK()
throws Exception { //Given PortfolioManagerBOportfolioManagerBO = newPortfolioManagerBO(); PortfolioFormportfolioForm = newPortfolioForm(); portfolioManagerBO.setPortfolioForm(portfolioForm); //When portfolioManagerBO.reglesValidationHRM118(); //Then assertFalse(portfolioForm.isMessageAVisible()); assertFalse(portfolioForm.isPopupVisible()); }
40.
Tip4 : Quoi
tester? “Bas niveau” : état privatestaticString formatValue(Object removeNull) { if(removeNull == null) { return""; } else { returnremoveNull.toString(); } }
41.
“Haut niveau” :
comportement public String getPointsHoraires(String dateDeb, String dateFin, String portFolios, String password) { passwordChecker.checkPassword(password); List<Long> listIdPortfolio = convertPortfoliosIdToLong(portFolios); List<Object[]> pointsResultats = executeCalculPointsPortefeuille( dateDeb, dateFin, listIdPortfolio); String pointsCSV= formatResultToCSV(pointsResultats); returnpointsCSV; }
42.
Bilan Aimez vos
tests et ils vous le rendront Les principes “Clean code” s’appliquent également au code de test!
43.
Ressources http://www.wakaleo.com/blog http://misko.hevery.com/
44.
Merci nrichand@xebia.fr http://blog.xebia.fr
Editor's Notes
3 symptomes :Plus d’assert@Test en commentaireCode commenté
MarketDataControllerBOTest
Chaque test porte une intention, un butOn ne teste pas une classe, mais plutôt un ensemble de comportement
Creation fixture (+varargs)Creation builder
Sortir les magic en constantes de classes
Plus facile pour détecter la méthodetestéeIncite à faire uneméthode de test = un testIncite à faire de petit tests
Fest
Fest
Fest
http://meetspock.appspot.com/Montrer:Nom de méthode en defGiven/When/Then : plus d’assertData Driven
http://meetspock.appspot.com/Montrer:Nom de méthode en defGiven/When/ThenData Driven
Inclus : Pas d’assertsur les init
Package private
Parler de dp4J : https://sites.google.com/a/mysimpatico.com/home//dp4j
Download now