Record method calls in one session for replaying in future test sessions?

前端 未结 9 1295
梦毁少年i
梦毁少年i 2020-12-23 14:21

I have a backend system which we use a third-party Java API to access from our own applications. I can access the system as a normal user along with other users, but I do no

9条回答
  •  一生所求
    2020-12-23 14:32

    you could look into 'Mockito'

    Example:

    //You can mock concrete classes, not only interfaces
    LinkedList mockedList = mock(LinkedList.class);
    
    //stubbing
    when(mockedList.get(0)).thenReturn("first");
    when(mockedList.get(1)).thenThrow(new RuntimeException());
    
    //following prints "first"
    System.out.println(mockedList.get(0));
    
    //following throws runtime exception
    System.out.println(mockedList.get(1));
    
    //following prints "null" because get(999) was not stubbed
    System.out.println(mockedList.get(999));
    

    after you could replay each test more times and it will return data that you put in.

提交回复
热议问题