Advertisement
ivana_andreevska

Junit Test 3

May 18th, 2022
611
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.junit.jupiter.api.AfterEach;
  2. import org.junit.jupiter.api.BeforeEach;
  3. import org.junit.jupiter.api.Test;
  4.  
  5. import static org.junit.jupiter.api.Assertions.*;
  6.  
  7. class CalculatorTest {
  8.     private final Calculator calculator=new Calculator();
  9.  
  10.     @BeforeEach
  11.     void beforeEachTest()
  12.     {
  13.         System.out.println("@BeforeEach - This method will start Before each test");
  14.     }
  15.     @AfterEach
  16.     void afterEachTest()
  17.     {
  18.         System.out.println("@AfterEach - This method will run after each test");
  19.     }
  20.     @Test
  21.     void divideNormalNumbers() {
  22.         System.out.println("Test divide normal number");
  23.         assertEquals(3,calculator.divide(9,3));
  24.         assertEquals(2,calculator.divide(4,2));
  25.         assertEquals(0,0,2);
  26.     }
  27.     @Test
  28.     void divideDecimalNumbers()
  29.     {
  30.         System.out.println("Divide decimal numbers");
  31.         assertEquals(2.25,calculator.divide(9,4));
  32.         assertEquals(0,calculator.divide(0,4.5));
  33.         assertEquals(0.5,calculator.divide(1,2));
  34.     }
  35. }
Advertisement
RAW Paste Data Copied
Advertisement