`
awdxzc
  • 浏览: 337000 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

spring mock

    博客分类:
  • J2EE
阅读更多
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

public class BaseTest extends
AbstractDependencyInjectionSpringContextTests {
	
	/**
	 * load spring configuration file
	 */
	public String[] getConfigLocations() {
		String[] configLocations = { "file:src/main/webapp/WEB-INF/config/applicationContext.xml" };
		return configLocations;
	}
	

	/**
	 * public String[] getConfigLocations() {
           String[] configLocations = { "applicationContext.xml","hibernate-context.xml" };
           return configLocations;
       } 
	 */

}


public class ContentModuleControllerTest extends BaseTest{
		
	
	ContentModuleService contentModuleService ;
	
	
	public void setContentModuleService(ContentModuleService contentModuleService)
	{
		this.contentModuleService = contentModuleService;
	}
	
	
    public void testGetProduct() {
        assertEquals("Eric test mock",contentModuleService.forTest("Eric test mock"));
    }
   
    public void testGetArticleByDate() {
//    	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/web/modules/articles/date");
//    	request.addParameter("debug", "true");
    	
    }
	
}


MockHttpServletRequest是模拟http请求,不是HttpClient类型的直接调用,MockHttpServletRequest 不需要服务器启动,单纯模拟,根据你自己的实际情况,选择你需要的访问请求模式。HttpClient用在需要response返回值比较的junit环境。




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics