EasyMock: Mock out a constructor call in java

前端 未结 4 1111
生来不讨喜
生来不讨喜 2021-01-05 03:11

I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on the object

4条回答
  •  借酒劲吻你
    2021-01-05 03:49

    And this is why you want to inject your dependencies (via Guice or similar package) instead of creating them inside your class.

    Then you don't HAVE TO mock their construction.

    This assumes (a) that this is your code that you can change, and (b) that the objects in question are complex enough that you should inject them. Constructing simple objects inside your class are fine, but then you shouldn't need to mock them.

提交回复
热议问题