随笔 - 16  文章 - 0  trackbacks - 0
<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

常用链接

留言簿

随笔档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜

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)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: