Mock constructor with mockito

后端 未结 3 933
温柔的废话
温柔的废话 2021-01-18 07:48

I want to mock a constructor into method.

public String generaID() {   
    GeneraIDParaEntidadCliente aux = new GeneraIDParaEntidadCliente(nombre, registro         


        
3条回答
  •  不要未来只要你来
    2021-01-18 08:17

    You can use PowerMock to mock constructors.

    If you can't use PowerMock for some reason, the most workable solution is to inject a factory to whatever class contains this method. You would then use the factory to create your GeneraIDParaEntidadCliente object and mock the factory.

提交回复
热议问题