Advertisement
ivana_andreevska

Junit Test 4

May 18th, 2022
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import org.junit.jupiter.api.*;
  2.  
  3. import static org.junit.jupiter.api.Assertions.*;
  4.  
  5. class CalculatorTest {
  6.     private final Calculator calculator=new Calculator();
  7.  
  8.     @BeforeAll
  9.     static void init()
  10.     {
  11.         System.out.println("@BeforeAll - This method will start before all methods");
  12.     }
  13.  
  14.     @AfterAll
  15.     static void destroy()
  16.     {
  17.         System.out.println("@AfterAll - This method will start after all methods");
  18.     }
  19.     @BeforeEach
  20.     void beforeEachTest()
  21.     {
  22.         System.out.println("@BeforeEach - This method will start Before each test");
  23.     }
  24.     @AfterEach
  25.     void afterEachTest()
  26.     {
  27.         System.out.println("@AfterEach - This method will run after each test");
  28.     }
  29.     @Test
  30.     void divideNormalNumbers() {
  31.         System.out.println("Test divide normal number");
  32.         assertEquals(3,calculator.divide(9,3));
  33.         assertEquals(2,calculator.divide(4,2));
  34.         assertEquals(0,0,2);
  35.     }
  36.     @Test
  37.     void divideDecimalNumbers()
  38.     {
  39.         System.out.println("Divide decimal numbers");
  40.         assertEquals(2.25,calculator.divide(9,4));
  41.         assertEquals(0,calculator.divide(0,4.5));
  42.         assertEquals(0.5,calculator.divide(1,2));
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement