mockDao = new Mock(Dao.class);
business = new Business();
}
protected void tearDown() throws Exception
{
mockDao = null;
business = null;
super.tearDown();
}
public void testOperate()
{
ArrayList stubList = new ArrayList();
stubList.add("test");
// 定义Mock剧本
mockDao.expects(once())// 期待次数
.method("execute")// 调用方法
.with(eq("select * from tbl_test"))// 传入参数等于
.will(this.returnValue(stubList));// 返回对象
Dao dao = (Dao) mockDao.proxy();
business.setDao(dao);
assertEquals(business.operate(), "test");
}
}
("execute")// 调用方法
.with(eq("select * from tbl_test"))// 传入参数等于软件测试
.will(this.returnValue(stubList));// 返回对象
Dao dao = (Dao) mockDao.proxy();
business.setDao(dao);
assertEquals(business.operate(), "test");
}
}
文章来源于领测软件测试网 https://www.ltesting.net/