有时候,需要测试的方法内有collections结构,就需要同时mock多个对象

被测方法:

public class EmployeeService {
    
    public List<Integer> getTotalLIst(){
        List<Integer> list = new ArrayList<Integer>();
        for (int i=0;i<10;i++){
            list.add(employeeDao.getTotal());
        }
        return list;
    }
}

测试类:

    @Test
    public void getTotalLIst(){
        PowerMockito.when(employeeDao.getTotal()).thenReturn(1,2,3,4,5,6,7,8,9,10);
        List<Integer> list = employeeService.getTotalLIst();
        List<Integer> listnew = new ArrayList<Integer>();
        for(int i=0;i<10;i++){
            listnew.add(i+1);
        }
        Assert.assertEquals(listnew, list);
    }

 

相关文章:

  • 2021-10-22
  • 2022-01-04
  • 2021-05-30
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-06-01
  • 2022-01-02
相关资源
相似解决方案