import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
/**
引入Spring配置文件,以便注入
**/
@ContextConfiguration(
locations = {"classpath:/mybatis-config.xml" ,
"classpath:/application-resources.xml",
"classpath:/application-dao.xml",
"classpath:/application-service.xml",
"classpath:/application-struts.xml"})
//继承AbstractTransactionalJUnit4SpringContextTests,实现事务回滚
public abstract class BaseTestCase extends AbstractTransactionalJUnit4SpringContextTests
{
}
使用例子如下:
import java.util.Date;
import java.util.UUID;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.*;
import com.deppon.yp.BaseTestCase;
import com.deppon.yp.entity.Province;
public class ProvinceSerivceTestCase extends BaseTestCase {
@Autowired
private IProvinceService provinceService;
@Test
public void save() {
Province province = new Province();
province.setId(UUID.randomUUID().toString());
province.setName("上海");
province.setSimpleName("沪");
province.setNumber("SH");
province.setDirect(true);
province.setDescription("test");
province.setCreateTime(new Date());
province.setLastUpdateTime(new Date());
assertEquals(1,this.getProvinceService().save(province));
}
public void setProvinceService(IProvinceService provinceService) {
this.provinceService = provinceService;
}
public IProvinceService getProvinceService() {
return provinceService;
}
}
posted on 2012-02-22 16:24
民工二代 阅读(1286)
评论(0) 编辑 收藏