What is BDD?

  Given some preconditions (Arrange) -> When an action occurs (Act) -> Then verify the output (Assert)

I.E.

  Given three items in Cart
  When one Item is deleted
  Then Two items should be left in Cart
@ExtendWith(MockitoExtension.class)
public class EmpServiceImplTest {

    @Mock
    EmployeeDB employeeDB;

    @InjectMocks
    EmpServiceImpl empServiceImpl;

    @Test
    @DisplayName("Check Employee in BDD Style")
    public void test_getEmployees_Success(){
        //Given - Employee List has only one row with List size as 1
        //When  - New Employee is added to the List
        //Then  -  Employee List should contain two rows

        //Given - Employee List has 3 Employees with List size as 3
        List<Employee> arrEmployees = new ArrayList<>();
        arrEmployees.add(new Employee("101", "Mugil"));
        arrEmployees.add(new Employee("102", "Max"));
        arrEmployees.add(new Employee("103", "Mani"));

        given(employeeDB.getEmployeesFromDB()).willReturn(arrEmployees);

        //When
        List<Employee> arrFilteredEmps = empServiceImpl.getEmployees();

        //Then - there should 3 EmployeegetEmployeeByIdFromDB
        Assertions.assertEquals(3, arrFilteredEmps.size());
    }
}

Comments are closed.