From cf655157f332ab04e31929a886f05415a4f8d089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Raya=20D=C3=89CORNOD?= Date: Thu, 5 Nov 2020 17:04:13 +0100 Subject: [PATCH 1/2] [#4] use cucumber & sceanrio --- build.gradle | 7 +++++-- .../mathinfo/gl/tp/demo/CucumberSupport.java | 8 ++++++++ .../unistra/mathinfo/gl/tp/demo/FizzBuzz.feature | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/test/java/fr/unistra/mathinfo/gl/tp/demo/CucumberSupport.java create mode 100644 src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature diff --git a/build.gradle b/build.gradle index 6be0f55..8d4de43 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 0000000..f3d3768 --- /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/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 0000000..e5e169a --- /dev/null +++ b/src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature @@ -0,0 +1,14 @@ +Feature: FizzBuzz + FizzBuzz pour division par 3 ou 5 + + Scenario Outline: Situations FizzBuzz + Given En tant que joueur en position + When C'est mon tour + Then Je dis + + Examples: + | nombre | attendu | + | 13 | 13 | + | 9 | Fizz | + | 20 | Buzz | + | 15 | FizzBuzz | -- GitLab From 8b08422f91eddc7c12ec258a482e9b98f46a0ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Raya=20D=C3=89CORNOD?= Date: Thu, 5 Nov 2020 17:34:38 +0100 Subject: [PATCH 2/2] [#4] steps & moar scenarii --- .../mathinfo/gl/tp/demo/steps/BDDSteps.java | 52 +++++++++++++++++++ .../mathinfo/gl/tp/demo/FizzBuzz.feature | 17 ++++-- 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/test/java/fr/unistra/mathinfo/gl/tp/demo/steps/BDDSteps.java 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 0000000..1129058 --- /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 index e5e169a..01c36e3 100644 --- a/src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature +++ b/src/test/resources/fr/unistra/mathinfo/gl/tp/demo/FizzBuzz.feature @@ -3,12 +3,23 @@ Feature: FizzBuzz Scenario Outline: Situations FizzBuzz Given En tant que joueur en position - When C'est mon tour - Then Je dis + When Je joue + Then J'ai dit - Examples: + 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 | -- GitLab