接下来创建一个具体的测试类,该类继承了父类SuperTest:
public class TestGoodsNewServiceImpl extends SuperTest {
private GoodsNewService goodsNewService;
protected void onSetUp() throws Exception {
super.onSetUp();
goodsNewService=(GoodsNewService)getContext(getConfigLocations()).getBean("goodsNewService");
}
//测试createGoodsSn方法
public void testCreateGoodsSn() throws Exception{
Goods goods=new Goods(1,null,"mygoods 1","",1,"","",new Date(),new Date(),"");
goodsNewService.addNewGoodsWithTransaction(goods);
String sn=null;
sn=goods.getGoodsSn();
assertTrue(sn!=null);
}
//测试addNewGoods方法
public void testAddNewGoods() throws Exception{
Goods goods=new Goods(1,"123456789","mygoods 1","",1,"","",new Date(),new Date(),"");
Object result=goodsNewService.addNewGoodsWithTransaction(goods);
assertTrue(result!=null);
}
//测试updateGoods方法
public void testUpdateGoods() throws Exception{
int id=430;
Goods goods=goodsNewService.getGoodsByIdWithReadOnly(id);
String name="new goods name";
goods.setGoodsName(name);
goodsNewService.updateGoodsWithTransaction(goods);
assertEquals(name, goodsNewService.getGoodsByIdWithReadOnly(id).getGoodsName());
}
//测试getGoodsById方法
public void testGetGoodsById() throws SQLException{
int id=430;
Goods goods=goodsNewService.getGoodsByIdWithReadOnly(id);
assertEquals(id, goods.getGoodsId());
}
//测试addGoodsBrand方法
public void testAddGoodsBrand(){
String brandName="Nokia 5550";
Object result=goodsNewService.addGoodsBrandWithTransaction(brandName);
assertTrue(result!=null);
}
//测试addGoodsCategory方法
public void testAddGoodsCategory(){
String categoryName="my phone";
int parentId=0;
Object result=goodsNewService.addGoodsCategoryWithTransaction(categoryName, parentId);
assertTrue(result!=null);
}
//测试getCategoryList方法
public void testGetCategoryList(){
List<GoodsCategory> list=goodsNewService.getCategoryListWithReadOnly();
assertTrue(list.size()>0);
}
//测试getCategoryList方法
public void testGetBrandList(){
List<GoodsBrand> list=goodsNewService.getBrandListWithReadOnly();
assertTrue(list.size()>0);
}
}
public class TestGoodsNewServiceImpl extends SuperTest {
private GoodsNewService goodsNewService;
protected void onSetUp() throws Exception {
super.onSetUp();
goodsNewService=(GoodsNewService)getContext(getConfigLocations()).getBean("goodsNewService");
}
//测试createGoodsSn方法
public void testCreateGoodsSn() throws Exception{
Goods goods=new Goods(1,null,"mygoods 1","",1,"","",new Date(),new Date(),"");
goodsNewService.addNewGoodsWithTransaction(goods);
String sn=null;
sn=goods.getGoodsSn();
assertTrue(sn!=null);
}
//测试addNewGoods方法
public void testAddNewGoods() throws Exception{
Goods goods=new Goods(1,"123456789","mygoods 1","",1,"","",new Date(),new Date(),"");
Object result=goodsNewService.addNewGoodsWithTransaction(goods);
assertTrue(result!=null);
}
//测试updateGoods方法
public void testUpdateGoods() throws Exception{
int id=430;
Goods goods=goodsNewService.getGoodsByIdWithReadOnly(id);
String name="new goods name";
goods.setGoodsName(name);
goodsNewService.updateGoodsWithTransaction(goods);
assertEquals(name, goodsNewService.getGoodsByIdWithReadOnly(id).getGoodsName());
}
//测试getGoodsById方法
public void testGetGoodsById() throws SQLException{
int id=430;
Goods goods=goodsNewService.getGoodsByIdWithReadOnly(id);
assertEquals(id, goods.getGoodsId());
}
//测试addGoodsBrand方法
public void testAddGoodsBrand(){
String brandName="Nokia 5550";
Object result=goodsNewService.addGoodsBrandWithTransaction(brandName);
assertTrue(result!=null);
}
//测试addGoodsCategory方法
public void testAddGoodsCategory(){
String categoryName="my phone";
int parentId=0;
Object result=goodsNewService.addGoodsCategoryWithTransaction(categoryName, parentId);
assertTrue(result!=null);
}
//测试getCategoryList方法
public void testGetCategoryList(){
List<GoodsCategory> list=goodsNewService.getCategoryListWithReadOnly();
assertTrue(list.size()>0);
}
//测试getCategoryList方法
public void testGetBrandList(){
List<GoodsBrand> list=goodsNewService.getBrandListWithReadOnly();
assertTrue(list.size()>0);
}
}