当前位置: 首页 > news >正文

电子商务网站建设过程报告推广团队在哪里找

电子商务网站建设过程报告,推广团队在哪里找,怎么用阿里云建设网站,wap网站源码 下载项目采用分层开发,服务端和客户端。服务端的开发需要测试,但是涉及到了servletrequest和servletresponse。这里提供两种方法。 1、easymock 2、springmock 第一种方法 代码Java代码 package com.zzrenfeng.util; import org.apache.commons.logging.…

项目采用分层开发,服务端和客户端。服务端的开发需要测试,但是涉及到了servletrequest和servletresponse。这里提供两种方法。

1、easymock

2、springmock

第一种方法

代码

 

Java代码  收藏代码
  1. package com.zzrenfeng.util;  
  2.   
  3. import org.apache.commons.logging.*;  
  4. import org.junit.*;  
  5. import org.junit.runner.*;  
  6. import org.springframework.mock.web.*;  
  7. import org.springframework.test.context.*;  
  8. import org.springframework.test.context.junit4.*;  
  9. import org.springframework.test.context.support.*;  
  10.   
  11. import com.zzrenfeng.util.meetingapp.*;  
  12.   
  13. /** 
  14.  *  
  15.  * @ClassName: UserServiceTest 
  16.  * @Description: 单主键jdbcdao测试 
  17.  * @author renjunjie 
  18.  * @date 2010-12-10 下午03:20:08 
  19.  * 
  20.  */  
  21. @RunWith(SpringJUnit4ClassRunner.class)  
  22. @TestExecutionListeners( { DependencyInjectionTestExecutionListener.class })  
  23. @ContextConfiguration(locations={ "classpath:resource/applicationContext-test.xml"})  
  24. public class HttpServletTest  {  
  25.   
  26.     private static final Log log = LogFactory.getLog(HttpServletTest.class);  
  27.   
  28.     private MockHttpServletRequest request;    
  29.     private MockHttpServletResponse response;    
  30.       
  31.     @Before  
  32.     public void setUp(){  
  33.         request = new MockHttpServletRequest();    
  34.         request.setCharacterEncoding("UTF-8");    
  35.         response = new MockHttpServletResponse();    
  36.           
  37.           
  38.     }  
  39.       
  40.     @Test  
  41.     public void test(){  
  42.           
  43.         SecurityApplication sa = new SecurityApplication();  
  44.           
  45.          //request.setRequestURI("/loginCheck.html");    
  46.         request.addParameter("userId""9001"); //直接添加request参数,相当简单  
  47.           
  48.         String result = sa.getPerson(request);  
  49.           
  50.         System.out.println(result);  
  51.     }  
  52.       
  53. }  

 第二种方法

 

Java代码  收藏代码
  1. package com.zzrenfeng.util;  
  2.   
  3. import javax.servlet.http.*;  
  4.   
  5. import org.apache.commons.logging.*;  
  6. import org.easymock.*;  
  7. import org.junit.*;  
  8. import org.junit.runner.*;  
  9. import org.springframework.test.context.*;  
  10. import org.springframework.test.context.junit4.*;  
  11. import org.springframework.test.context.support.*;  
  12.   
  13. import com.zzrenfeng.util.meetingapp.*;  
  14.   
  15. /** 
  16.  *  
  17.  * @ClassName: UserServiceTest 
  18.  * @Description: 单主键jdbcdao测试 
  19.  * @author renjunjie 
  20.  * @date 2010-12-10 下午03:20:08 
  21.  * 
  22.  */  
  23. @RunWith(SpringJUnit4ClassRunner.class)  
  24. @TestExecutionListeners( { DependencyInjectionTestExecutionListener.class })  
  25. //@ContextConfiguration(locations={ "file:WebContent/WEB-INF/red5-web.xml"})  
  26. @ContextConfiguration(locations={ "classpath:resource/applicationContext-test.xml"})  
  27. public class HttpServletTest2  {  
  28.   
  29.     private static final Log log = LogFactory.getLog(HttpServletTest2.class);  
  30.   
  31.     private HttpServletRequest request;    
  32.     private HttpServletResponse response;    
  33.       
  34.     @Before  
  35.     public void setUp(){  
  36.               
  37.         //创建request和response的Mock    
  38.         request = (HttpServletRequest)EasyMock.createMock(HttpServletRequest.class);    
  39.         response = (HttpServletResponse) EasyMock.createMock(HttpServletResponse.class);    
  40.     }  
  41.       
  42.     @Test  
  43.     public void test(){  
  44.           
  45.         SecurityApplication sa = new SecurityApplication();  
  46.           
  47.       
  48.           
  49.         EasyMock.expect(request.getParameter("opens")).andReturn("123").once();    //期望使用参数  
  50.         EasyMock.expect(request.getParameter("userId")).andReturn("9001").times(2);  //期望调用的次数  
  51.   
  52.         EasyMock.replay(request);   //保存期望结果  
  53.           
  54.         String result = sa.getPersonMeetings3G(request);  
  55.           
  56.         System.out.println(result);  
  57.     }  
  58.       
  59. }  

 EasyMock主要是为测试提供模拟数据,比如你可以模拟HttpServletRequest。 

 EasyMock 可以mock interface和抽象java 类,但是不可以mock拥有被final修饰方法的类,不能mock静态方法(我遇到的情况是这样)。 
在使用的时候请注意: 
org.easymock.classextension.EasyMock 被用来mock抽象类(abstract)和具体类 
org.easymock.EasyMock被用来mock接口(interface) 

使用用EasyMock的一般步骤: 
1.创建一个mock对象 
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class); 
2.设置此对象的某个方法的返回值 
EasyMock.expect(request.getParameter("userName")).andReturn("trilogy").once(); 
注意:必须手工设置被mock的方法的访问次数 
once() 
antyTimes() 
times(int) 
建议:在设置方法调用次数的时候,虽然你可以调用anyTimes(),但是最好明确你要调用多少次如:once()、 
times(2),这样做的话显的比较严谨。 

如果mock的方法没有返回值,可以这么做: 
request.setAttribute("userId"); 
EasyMock.expectLastCall().once(); 

对于被mock的方法参数,也可以不必指定具体的值: 
EasyMock.expect(request.getParameter((String)EasyMock.anyObject())).andReturn("trilogy").once(); 

如果你想让被mock的方法返回一个异常,前提是被mock的方法会抛出异常,你可以这么做: 
EasyMock.expect(input.read()).andThrow(new IOException("Mocked IOException")).once(); 

你还可以根据调用顺序来mock同一个方法: 
EasyMock.expect(request.getParameter("userName")).andReturn("trilogy").once(); 
EasyMock.expect(request.getParameter("userName")).andReturn(null).once(); 
当第一次执行request.getParameter("userName")的时候,返回“trilogy” 
当第二次执行request.getParameter("userName")的时候,返回null 

3.保存被mock的对象 
EasyMock.replay(a); 

4.在被mock的对象被应用之后,最好验证一下我们所设置的mock对象是不是按我们预期运行。 
EasyMock.verify(a); 

总结: 
EasyMock是一个相当方便的mock工具,可以为我们的测试工作提供极大的便利,特别是在测试web层或者数据库访问的时候。 
在这里我只是抛砖引玉地介绍了一下EasyMock的使用,其实EasyMock还有很多其它更高级的使用,如过你愿意的话可以访问以下的网址来获得更多信息: 
官网:www.easymock.org 

http://www.lbrq.cn/news/2467333.html

相关文章:

  • 媒体查询做响应式网站网站权重排名
  • 下了网站建设搜索引擎营销的步骤
  • 网站怎么推广引流上海十大公关公司排名
  • 网站域名管理在哪里韩国网站
  • 外贸网站怎么做优化百度浏览器下载安装2023版本
  • 用墨刀做视频网站长沙今日头条新闻
  • 湖南做网站的公司排名软文推广网
  • asp网站后台管理系统源码网络营销岗位有哪些
  • 广告网站建设流程百度sem竞价托管公司
  • 网站规划建设前期规划方案网站安全检测平台
  • 上海外贸soho网站建设女儿考试没圈关键词
  • wordpress 本机安装阜新网站seo
  • 装修网站建设方案书网络营销策划方案书范文
  • 哈尔滨网站建设效果好aso优化师
  • 网站域名怎么写最好的bt磁力搜索引擎
  • 网站图片地址怎么做的商丘网络推广公司
  • 手机app设计网站网络营销方案设计毕业设计
  • 人才招聘网站开发怎么做线上推广
  • 做响应式网站对设计图的要求长春网站制作设计
  • 做漫画在线观看网站seo软件工具箱
  • 浙江省建设银行网站首页地推网
  • 旅游网站前端建设毕业论文搜索引擎优化网站排名
  • 中企动力是什么公司荆州网站seo
  • 网站播放大视频如何做今日国际重大新闻事件
  • 十大导航软件网络舆情优化公司
  • 自己建设网站用哪个全网搜索软件下载
  • 免费自助建站网站seo诊断技巧
  • 自己建设网站步骤百度app下载安装 官方
  • 邢台移动网站建设费用自己怎么优化网站
  • 电子商务公司设计网站建设惠州seo网站管理
  • 【408二轮强化】数据结构——线性表
  • CT、IT、ICT 和 DICT区别
  • 智慧水库管理平台数据清洗实施方案
  • HTML5 Canvas 绘制圆弧效果
  • Android 修改系统时间源码阅读
  • Qt 远程过程调用(RPC)实现方案