SlideShare une entreprise Scribd logo
1  sur  20
FestAssert : les assertions plus lisible
Assertion ? ,[object Object],[object Object]
Avec quoi les écrire ? ,[object Object],[object Object],[object Object],[object Object],[object Object]
JUnit - Ecrire assertion ,[object Object],[object Object],[object Object],[object Object],[object Object]
JUnit - Ecrire assertion Ah bon, je croyais que je devais formuler une proposition ?
JUnit - Ecrire assertion Ben si, regarde : List<Employe> partipants = bof.getParticipants(); assertNotNull(participants);  assertEquals(20, partipants.size()); La syntaxe de la 2ème assertions est bizarre... Ca me fait penser à quelqu'un.... mais qui ?
JUnit - Yoda assertions assertEquals(20, partipants.size());   Je souhaite que égal à 20 soit le nombre de participants
JUnit Oulah, je vais devoir parler comme Yoda. Et si jamais, j'ai besoin d'un assertTrue, ça va être compliqué... . Je veux seulement vérifier que le nombre de partipants est de 20.
FestAssert Heureusement non : assertThat(participants).hasSize(20);
FestAssert - Junit Je dois changer mon framework de test alors ? Non, pas du tout, FestAssert fait s'occupe seulement des assertions.
FestAssert Lexique plus riche, plus simple assertThat(partipants).doesNotHaveDuplicate();    Et en plus, je peux chainer tout ça : assertThat(partipants).isNotNull().hasSize(20) .doesNotHaveDuplicate();   
FestAssert - Syntaxe ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Vérifier présence de certains ? List<Employe> partipants = bof.getParticipants(); Employe nicolas = sfeir.getXXX Employe fabien = sfeir.getXXX assertThat(partipants).contains(nicolas, fabien); Pas super... Vérification liste
Fournit un ListAssert d'une liste transformée : List<A> => List<B> assertThat(partipants).onProperty(&quot;prenom&quot;) .contains(&quot;Nicolas&quot;, &quot;Fabien&quot;); onProperty
Failure 1/2 Parfois l'assertion est fausse : @Test public void junitListe() {     assertEquals(20, liste.size()); }   @Test public void festassertListe() {     Assertions.assertThat(liste).hasSize(20); }  
Failure 2/2 Des fois l'assertion est fausse : @Test public void junitString() {     assertNotNull(nom); }   @Test public void festAssertString() {     assertThat(nom).isNotNull(); }  
FestAssert - Extension Y'a même pas la méthode que je veux dans le xxxAssert
FestAssert - Syntaxe J'écris ma condition ! private class IsListeTailleImpaireCondition extends Condition<List<?>> {       @Override public boolean matches(List value) {            if(value == null){                return false;            } else {                return value.size()%2==1;            }        }    }    Et je m'en sers :  assertThat(maListe).satifies(new IsListeTailleImpaireCondition());    assertThat(maListe).doesNotsatify(new IsListeTailleImpaireCondition());    
FestAssert - Extension Y'a même pas le xxxAssert pour mon objet métier
FestAssert - Mon xxxAssert à moi J'écris mon xxxAssert : public class DateTimeAssert extends GenericAssert<DateTimeAssert, DateTime> {   public DateTimeAssert(DateTime actual) {          super(DateTimeAssert.class, actual);    }   public DateTimeAssert isBetween(DateTime begin, DateTime end){       isNotNull();      if(actual.compareTo(begin) >= 0 && actual.compareTo(end) <= 0) {            return this;          } throw failure(inBrackets(actual), &quot; should be between :&quot;, inBrackets(begin), &quot; and &quot;, inBrackets(end)));       }    } Et je m'en sers : MyAssertions.assertThat(maDate).isBeetwen(debutPeriode,finPeriode);

Contenu connexe

En vedette

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

En vedette (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Fest assert : les assertions plus lisibles

  • 1. FestAssert : les assertions plus lisible
  • 2.
  • 3.
  • 4.
  • 5. JUnit - Ecrire assertion Ah bon, je croyais que je devais formuler une proposition ?
  • 6. JUnit - Ecrire assertion Ben si, regarde : List<Employe> partipants = bof.getParticipants(); assertNotNull(participants);  assertEquals(20, partipants.size()); La syntaxe de la 2ème assertions est bizarre... Ca me fait penser à quelqu'un.... mais qui ?
  • 7. JUnit - Yoda assertions assertEquals(20, partipants.size());   Je souhaite que égal à 20 soit le nombre de participants
  • 8. JUnit Oulah, je vais devoir parler comme Yoda. Et si jamais, j'ai besoin d'un assertTrue, ça va être compliqué... . Je veux seulement vérifier que le nombre de partipants est de 20.
  • 9. FestAssert Heureusement non : assertThat(participants).hasSize(20);
  • 10. FestAssert - Junit Je dois changer mon framework de test alors ? Non, pas du tout, FestAssert fait s'occupe seulement des assertions.
  • 11. FestAssert Lexique plus riche, plus simple assertThat(partipants).doesNotHaveDuplicate();   Et en plus, je peux chainer tout ça : assertThat(partipants).isNotNull().hasSize(20) .doesNotHaveDuplicate();  
  • 12.
  • 13. Vérifier présence de certains ? List<Employe> partipants = bof.getParticipants(); Employe nicolas = sfeir.getXXX Employe fabien = sfeir.getXXX assertThat(partipants).contains(nicolas, fabien); Pas super... Vérification liste
  • 14. Fournit un ListAssert d'une liste transformée : List<A> => List<B> assertThat(partipants).onProperty(&quot;prenom&quot;) .contains(&quot;Nicolas&quot;, &quot;Fabien&quot;); onProperty
  • 15. Failure 1/2 Parfois l'assertion est fausse : @Test public void junitListe() {     assertEquals(20, liste.size()); }   @Test public void festassertListe() {     Assertions.assertThat(liste).hasSize(20); }  
  • 16. Failure 2/2 Des fois l'assertion est fausse : @Test public void junitString() {     assertNotNull(nom); }   @Test public void festAssertString() {     assertThat(nom).isNotNull(); }  
  • 17. FestAssert - Extension Y'a même pas la méthode que je veux dans le xxxAssert
  • 18. FestAssert - Syntaxe J'écris ma condition ! private class IsListeTailleImpaireCondition extends Condition<List<?>> {       @Override public boolean matches(List value) {            if(value == null){                return false;            } else {                return value.size()%2==1;            }        }    }    Et je m'en sers :  assertThat(maListe).satifies(new IsListeTailleImpaireCondition());   assertThat(maListe).doesNotsatify(new IsListeTailleImpaireCondition());  
  • 19. FestAssert - Extension Y'a même pas le xxxAssert pour mon objet métier
  • 20. FestAssert - Mon xxxAssert à moi J'écris mon xxxAssert : public class DateTimeAssert extends GenericAssert<DateTimeAssert, DateTime> {   public DateTimeAssert(DateTime actual) {          super(DateTimeAssert.class, actual);    }   public DateTimeAssert isBetween(DateTime begin, DateTime end){      isNotNull();     if(actual.compareTo(begin) >= 0 && actual.compareTo(end) <= 0) {            return this;          } throw failure(inBrackets(actual), &quot; should be between :&quot;, inBrackets(begin), &quot; and &quot;, inBrackets(end)));      }   } Et je m'en sers : MyAssertions.assertThat(maDate).isBeetwen(debutPeriode,finPeriode);