EasyMock期望私有方法调用 [英] EasyMock expecting private method calls

查看:116
本文介绍了EasyMock期望私有方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个看起来像这样的方法:

Lets say I have a method that looks like this:

public static String[] parseFoo(Foo anObject){
    Foo anotherObject = parseFoo2(anObject);
...
}

private static Foo parseFoo2(Foo anObject){
...
}

这两个方法都在同一类中。 parseFoo2只是一个帮助方法,可以帮助parseFoo完成一些工作。我正在尝试测试parseFoo方法。 EasyMock中是否有人可以在parseFoo2的私有方法调用上指定返回值,例如我可以为

and both methods are in the same class. parseFoo2 is just a helper method that helps parseFoo get some stuff done. I'm trying to test the method parseFoo. Is there anyone in EasyMock that I can specify a return value on that private method call for parseFoo2 like the way I can specify instance method calls for an object with

EasyMock.createMock(...);
anObject.expect(...).andReturn(...);

因为我想测试公共方法,但是我不想进入私有方法并在内部测试实现。

because I want to test the public method, but I don't want to have to go into the private method and test the implementation inside.

谢谢

推荐答案

如果发现自己必须模拟出私有方法,则可以使用 PowerMock.expectPrivate() 。 EasyMock无法模拟私有方法。

If you find that you must mock out a private method, then you can use PowerMock.expectPrivate(). EasyMock is not capable of mocking private methods.

这篇关于EasyMock期望私有方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆