java构造方法怎么mock_EasyMock:在java中模拟一个构造函数调用

我在这个板上看了类似的问题,但没有一个回答我的问题.这听起来很奇怪,但是可以在你正在嘲笑的对象上模拟一个构造函数调用.

例:

class RealGuy {

....

public void someMethod(Customer customer) {

Customer customer = new Customer(145);

}

}

class MyUnitTest() {

public Customer customerMock = createMock(Customer.class)

public void test1() {

//i can inject the mock object, but it's still calling the constuctor

realGuyobj.someMethod(customerMock);

//the constructor call for constructor makes database connections, and such.

}

}

我怎么能期待一个构造函数调用?我可以更改Customer构造函数调用以使用newInstance,但我不确定这是否有帮助.我无法控制新Customer(145)构造函数的主体.

这可能吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值