junit3测试spring下的service层
2010-01-21 22:35
375 查看
收藏
如果你已经整合好了hibernate和spring,那么恭喜你。如果你需要测试业务层,那么或许能给你帮助。
在已经写好的service右击,选择new---> Junit test case, 选1.3,选setup(),选一个要测试的方法。
例如
public class HotelService {
/** * @param args */ private CountryDAO countryDao; public List getCountryList() { List list=new ArrayList(); countryDao.findById(1); System.out.println("记录"); return list; } public CountryDAO getCountryDao() { return countryDao; } public void setCountryDao(CountryDAO countryDao) { this.countryDao = countryDao; }
}
生成的
public class HotelServiceTest extends TestCase
{
private Country country;
//以下是取得ctx 的两种方式。绝对路径和相对路径。
ApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath*:applicationContext.xml");
/* ApplicationContext ctx = new FileSystemXmlApplicationContext( "file:D:/Eclipse3.2/SpringTest2/WebRoot/WEB-INF/classes/applicationContext.xml"); */
CountryDAO countryDao = (CountryDAO) ctx.getBean("CountryDAO");
protected void setUp() throws Exception
{
super.setUp();
}
public void testGetCountryList()
{
country=countryDao.findById(1);
System.out.println(country.getCtEname());
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yangjiehuan/archive/2008/06/25/2586115.aspx
如果你已经整合好了hibernate和spring,那么恭喜你。如果你需要测试业务层,那么或许能给你帮助。
在已经写好的service右击,选择new---> Junit test case, 选1.3,选setup(),选一个要测试的方法。
例如
public class HotelService {
/** * @param args */ private CountryDAO countryDao; public List getCountryList() { List list=new ArrayList(); countryDao.findById(1); System.out.println("记录"); return list; } public CountryDAO getCountryDao() { return countryDao; } public void setCountryDao(CountryDAO countryDao) { this.countryDao = countryDao; }
}
生成的
public class HotelServiceTest extends TestCase
{
private Country country;
//以下是取得ctx 的两种方式。绝对路径和相对路径。
ApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath*:applicationContext.xml");
/* ApplicationContext ctx = new FileSystemXmlApplicationContext( "file:D:/Eclipse3.2/SpringTest2/WebRoot/WEB-INF/classes/applicationContext.xml"); */
CountryDAO countryDao = (CountryDAO) ctx.getBean("CountryDAO");
protected void setUp() throws Exception
{
super.setUp();
}
public void testGetCountryList()
{
country=countryDao.findById(1);
System.out.println(country.getCtEname());
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yangjiehuan/archive/2008/06/25/2586115.aspx
相关文章推荐
- junit3测试spring下的service层
- JavaEE_Junit_Junit对Spring注入的Service层的测试
- springboot集成junit测试与javamail测试遇到的问题
- spring + junit 测试
- spring junit完美测试解决方案
- SpringMVC+Spring+hibernate+junit的Dao测试
- 用Spring提供的JUnit框架扩展对DAO或Service层进行单元测试
- Junit+spring创建JNDI运行测试用例
- spring - 使用 IDEA编译工具: Junit测试
- spring dbunit junit hibernate 注解方式测试集合
- Junit使用教程--整合spring测试套件
- SpringBoot中Junit测试注入Bean失败的解决方法
- Spring整合JUnit实现测试用例
- Spring+EasyMock对Service层方法进行测试,处理@Resource属性
- spring AOP 配置事务不起作用的问题(用Junit测试service)
- Spring Test, JUnit, Mockito, Hamcrest 集成 Web 测试
- spring junit 部署两套测试方案
- spring下的junit测试
- JUnit 测试 Spring