我是junit的新手。我需要为以下方法做junit。请指导我
public boolean binlist(params hpproxy, calendarparam cpxproxy)
{
Getbinresponse binresponse;
cpproxy.setid(hpproxy.getId());
binresponse= cpproxy.getBinlist(); // resturns a list calling webservice
if (binresponse.size>0)
{
result=true;
}
else
{
result=false;
}
return result;
}
我尝试使用模拟对象测试 binlist 方法。
class testbin
{
@test
public void testbinlist()
{
Testbin mocktestbin=mock(testbin.class);
calendarproxy cpproxy=mock(calendarproxy.class);
params hpproxy= mock(cparams.class);
hpproxy.setId("123");
stub(cpproxy.getBinList()).toReturn(gettestbins()) // mocked getbinlist()
boolen result= mocktestbin.binlist();
assertTrue(result);
}
}
如何在方法中测试 Web 服务?