开发者

Mock an object in a method that is not a parameter in java similar to the following python code?

following is a very cool mocking with python, is there anyway to do that also in java?

mockpath = os.path
mockpath.isdir = Mock(return_value=False)
myObj = MyClass()
myObj.invoke_some_method()
myObj.some_other_method.assert_called_with(False)

is anything like this possible in java? meaning updati开发者_如何学运维ng the return values and behavior of objects instantiated inside other object methods in such a convenient way? any framework to do that so nicely?

thanks


Mockito supports partial mocks as well as mocking out a method in a real class. The latter looks more similar to your Python example.

I believe EasyMock supports the same thing but I'm having trouble finding where it is in the documentation.


I found that powermock library is the most suitable for this in java and most resembels mocks.py

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜