diff --git a/build.gradle b/build.gradle index 6be0f554447eaab5f40ff4415be66a601730261a..8d4de439aa65a6f54434c8d39bad94331f071265 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,11 @@ plugins { sourceCompatibility = 1.11 dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + + testImplementation 'io.cucumber:cucumber-java:6.8.2' + testImplementation 'io.cucumber:cucumber-junit-platform-engine:6.8.2' } test { diff --git a/src/test/java/fr/unistra/mathinfo/gl/tp/demo/CucumberSupport.java b/src/test/java/fr/unistra/mathinfo/gl/tp/demo/CucumberSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..f3d376886d2cdcf18106e8a6a50fd301d193d1d4 --- /dev/null +++ b/src/test/java/fr/unistra/mathinfo/gl/tp/demo/CucumberSupport.java @@ -0,0 +1,8 @@ +package fr.unistra.mathinfo.gl.tp.demo; + +import io.cucumber.junit.platform.engine.Cucumber; + +@Cucumber +public class CucumberSupport { + +} diff --git a/src/test/java/fr/unistra/mathinfo/gl/tp/demo/steps/BDDSteps.java b/src/test/java/fr/unistra/mathinfo/gl/tp/demo/steps/BDDSteps.java new file mode 100644 index 0000000000000000000000000000000000000000..11290584c36e0c3aa09db33ee18000352b03e302 --- /dev/null +++ b/src/test/java/fr/unistra/mathinfo/gl/tp/demo/steps/BDDSteps.java @@ -0,0 +1,52 @@ +package fr.unistra.mathinfo.gl.tp.demo.steps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import fr.unistra.mathinfo.gl.tp.demo.FizzBuzz; +import fr.unistra.mathinfo.gl.tp.demo.FizzBuzzImpl; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class BDDSteps { + + private static class State { + private FizzBuzz fizzBuzz; + private int nombre; + private String resultat; + public Exception erreur; + } + private State state; + + @Given("En tant que joueur en position {int}") + public void en_tant_que_joueur_en_position(int nombre) { + state = new State(); + state.nombre = nombre; + state.fizzBuzz = new FizzBuzzImpl(); + } + + @When("Je joue") + public void je_joue() { + try { + state.resultat = state.fizzBuzz.convert(state.nombre); + } catch (Exception e) { + state.erreur = e; + } + } + + @Then("J'ai dit {word}") + public void j_ai_dit(String attendu) { + if (state.erreur != null) fail(state.erreur); + assertEquals(attendu, state.resultat); + } + + @Then("Une erreur {word} s'est produite") + public void erreur(String erreur) { + if (state.erreur == null + || ! erreur.equals(state.erreur.getClass().getSimpleName())) + fail("Aucune erreur " + erreur + " ne s'est produite"); + } + +} diff --git a/src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature b/src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature new file mode 100644 index 0000000000000000000000000000000000000000..01c36e394ea4542cb8e929ad10ad34ffb22aee6a --- /dev/null +++ b/src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature @@ -0,0 +1,25 @@ +Feature: FizzBuzz + FizzBuzz pour division par 3 ou 5 + + Scenario Outline: Situations FizzBuzz + Given En tant que joueur en position + When Je joue + Then J'ai dit + + Examples: + | nombre | attendu | + | 13 | 13 | + | 9 | Fizz | + | 20 | Buzz | + | 15 | FizzBuzz | + + Scenario Outline: Situations inattendues FizzBuzz + Given En tant que joueur en position + When Je joue + Then Une erreur s'est produite + + Examples: + | nombre | erreur | + | -5 | IllegalArgumentException | + | 0 | IllegalArgumentException | + | 101 | IllegalArgumentException |