From 2c10fd552c1a3cc9f16d98a9dfdf42ca5e676cef Mon Sep 17 00:00:00 2001 From: Laurent Pierron <Laurent.Pierron@inria.fr> Date: Sun, 29 Jan 2023 18:38:45 +0100 Subject: [PATCH] Moving tests in Junit5 CalcEngineTest.java --- .../java/fr/nancy/iut/CalcEngineTester.java | 74 ------------------- .../java/fr/nancy/iut/CalcEngineTest.java | 61 +++++++-------- 2 files changed, 26 insertions(+), 109 deletions(-) delete mode 100755 src/main/java/fr/nancy/iut/CalcEngineTester.java diff --git a/src/main/java/fr/nancy/iut/CalcEngineTester.java b/src/main/java/fr/nancy/iut/CalcEngineTester.java deleted file mode 100755 index dc31dd9..0000000 --- a/src/main/java/fr/nancy/iut/CalcEngineTester.java +++ /dev/null @@ -1,74 +0,0 @@ -package fr.nancy.iut; - -/** - * Test the CalcEngine class. - * - * @author Hacker T. Largebrain - * @version 1.0 - */ -// package calculator; - -public class CalcEngineTester -{ - // The engine to be tested. - private CalcEngine engine; - - /** - * Constructor for objects of class CalcEngineTester - */ - public CalcEngineTester() - { - engine = new CalcEngine(); - } - - /** - * Test everything. - */ - public void testAll() - { - System.out.println("Testing the addition operation."); - System.out.println("The result is: " + testPlus()); - System.out.println("Testing the subtraction operation."); - System.out.println("The result is: " + testMinus()); - System.out.println("All tests passed."); - } - - /** - * Test the plus operation of the engine. - * @return the result of calculating 3+4. - */ - public int testPlus() - { - // Make sure the engine is in a valid starting state. - engine.clear(); - // Simulate the key presses: 3 + 4 = - engine.numberPressed(3); - engine.plus(); - engine.numberPressed(4); - engine.equals(); - // Return the result, which should be 7. - return engine.getDisplayValue(); - } - - /** - * Test the minus operation of the engine. - * @return the result of calculating 9 - 4. - */ - public int testMinus() - { - // Make sure the engine is in a valid starting state. - engine.clear(); - // Simulate the presses: 9 - 4 = - engine.numberPressed(9); - engine.minus(); - engine.numberPressed(4); - engine.equals(); - // Return the result, which should be 5. - return engine.getDisplayValue(); - } - - public static void main(String[] args) { - CalcEngineTester tester = new CalcEngineTester(); - tester.testAll(); - } -} diff --git a/src/test/java/fr/nancy/iut/CalcEngineTest.java b/src/test/java/fr/nancy/iut/CalcEngineTest.java index 91a1e4e..f9138b6 100644 --- a/src/test/java/fr/nancy/iut/CalcEngineTest.java +++ b/src/test/java/fr/nancy/iut/CalcEngineTest.java @@ -1,50 +1,41 @@ package fr.nancy.iut; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -public class CalcEngineTest { - @Test - void testClear() { - - } - - @Test - void testEquals() { - - } - - @Test - void testGetAuthor() { - - } - - @Test - void testGetDisplayValue() { - - } - - @Test - void testGetTitle() { - - } +import static org.junit.jupiter.api.Assertions.assertEquals; - @Test - void testGetVersion() { +public class CalcEngineTest { - } + private final CalcEngine engine = new CalcEngine(); @Test + @DisplayName("Testing the subtraction operation : 9 - 4 = 5") void testMinus() { - - } - - @Test - void testNumberPressed() { - + // Make sure the engine is in a valid starting state. + engine.clear(); + // Simulate the presses: 9 - 4 = + engine.numberPressed(9); + engine.minus(); + engine.numberPressed(4); + engine.equals(); + // Return the result, which should be 5. + assertEquals(5, engine.getDisplayValue()); } @Test + @DisplayName("TTesting the addition operation : 3 + 4 = 7") void testPlus() { - + // Make sure the engine is in a valid starting state. + engine.clear(); + // Simulate the key presses: 3 + 4 = + engine.numberPressed(3); + engine.plus(); + engine.numberPressed(4); + engine.equals(); + // Return the result, which should be 7. + assertEquals(7, engine.getDisplayValue()); } + } -- GitLab