On Github bsautel / your-tests-need-love
Conséquences
Injection de dépendances
Conséquences
Non respect : Carré rectangle
public class Rectangle { private final int width; private final int length; public Rectangle(int width, int length) { this.width = width; this.length = length; } public int getLength() { return length; } public int getWidth() { return width; } }
public class Square extends Rectangle { public Square(int length) { super(length, length); } }
public class Rectangle { private int width; private int length; public Rectangle(int width, int length) { this.width = width; this.length = length; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getLength() { return length; } public void setLength(int length) { this.length = length; } }
public class Square extends Rectangle { public Square(int length) { super(length, length); } @Override public void setWidth(int width) { super.setWidth(width); // What about the length? } @Override public void setLength(int length) { super.setLength(length); // What about the width? } }
throw new UnsupportedOperationException();
Fort couplage entre classes du même arbre d'héritage
En Java / PHP (modèle héritage unique):
Mock = magie. Ce n'est pas la solution à tout.
Solutions pour subsituer un objet:
assertThat(france.getCapital()).isEqualTo("Paris");
assertThat(france.getPopulation()) .isGreaterThan(65000000) .isLessThan(70000000);
List<String> biggestCities = france.getThreeBiggestCities(); // At least assertThat(biggestCities).contains("Paris", "Marseille"); // Exactly assertThat(biggestCities).containsExactly("Paris", "Marseille", "Lyon"); // Only but in any order assertThat(biggestCities).containsOnly("Marseille", "Lyon", "Paris");Exemple : AssertJ en Java
Réalisée avec Reveal.js
Code source sur Github
Visible en ligne sur http://files.fierdecoder.fr/your-tests-need-love/
Liens vers des pages web citées pendant la présentation.