版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、Beyond TechnologyJUnit及STC進行單體測試(二)(Ver1.0)1目的與目標StrutsTestCase for JUnit介紹STC提供的兩種測試方式STC的配置使用STC示例2課程概述實際項目需要JUnit的不足STC的優(yōu)勢3StrutsTestCase for JUnit4StrutsTestCase提供的兩種途徑采用模擬對象途徑采用Cactus來真實的運行Struts的ActionServlet5Cactus測試框架的配置修改web.xml文件建立perties文件 指定日志文件配置strutstest包6修改web.xml文件a. 增加一個filter Filt
2、erRedirector org.apache.cactus.server.FilterTestRedirector 增加相應的filter mapping FilterRedirector /FilterRedirector b. 增加兩個servlet JspRedirector jsp- ServletRedirector org.apache.cactus.server.ServletTestRedirector 增加相應的servlet mapping JspRedirector /JspRedirector ServletRedirector /ServletRedirector
3、7建立perties文件在當前工程文件夾下的src下,新建文件:perties,內容如下:# Configuration Cactus.# Each project using Cactus need to have such a in the client side# CLASSPATH (Meaning the directory containgin this be in the client# side CLASSPATH, not the of course . :) )# Defines the URLs that will be used by Cactus to call it
4、s redirectors.# You need to specify in these URLs the webapp context that you use for your# application. In the example below, the context is test.# Web app Context under which our application to test runscactus.contextURL=1# Default Servlet Redirector Name. Used by ServletTestCase test cases.cactus
5、.servletRedirectorName = ServletRedirector# Default JSP Redirector Name. Used by JspTestCase test cases.cactus.jspRedirectorName = JspRedirector# NOTE: Some servlet 2.3 containers need to map the filter to a valid# resource (Orion 1.5.2 for example). Others, like Tomcat, are happy# with just any map
6、ping.# For example, the following would work with Tomcat (and this is what I would# have expected !) :# cactus.filterRedirectorName = FilterRedirectorcactus.filterRedirectorName=/FilterRedirector# Enable Cactus internal loggingcactus.enableLogging=true1 端口號應寫實際你所使用的端口號。8建立log_perties文件在當前工程文件夾下的src下
7、,新建文件:log_perties,內容如下:# Properties for configuring Log4j# This is the configuring for logging on the JUnit side (i.e. the client side)log4j.appender.cactus = org.apache.log4j.log4j.appender.cactus.1log4j.appender.cactus.Append = falselog4j.appender.cactus.layout = org.apache.log4j.PatternLayoutlog4
8、j.appender.cactus.layout.ConversionPattern = %dABSOLUTE %t %-5p %-30.30c2 %x - %m %n# Any application log which uses Log4J will be logged to the Cactus log filelog4j.rootCategory=DEBUG, cactus# By default we dont log at the DEBUG level for Cactus log, in order not to generate too# many logs. However
9、, should a problem arise and logs need to be sent to the Cactus dev team,# then we will ask you to change this to DEBUG.apache.cactus = WARN, cactus.apache.cactus=false1 指定日志文件的位置與名稱,如果指定的文件夾不存在,則會自動創(chuàng)建。9建立log_perties文件在當前工程文件夾下的src下,新建文件:log_perties,內容如下:# Properties for configuring Log4j# This is t
10、he configuring for logging on the server sidelog4j.appender.cactus = org.apache.log4j.log4j.appender.cactus.1log4j.appender.cactus.Append = falselog4j.appender.cactus.layout = org.apache.log4j.PatternLayoutlog4j.appender.cactus.layout.ConversionPattern = %dABSOLUTE %t %-5p %-30.30c2 %x - %m %n# Any
11、application log which uses Log4J will be logged to the Cactus log filelog4j.rootCategory=DEBUG, cactus# By default we dont log at the DEBUG level for Cactus log, in order not to generate too# many logs. However, should a problem arise and logs need to be sent to the Cactus dev team,# then we will as
12、k you to change this to DEBUG.apache.cactus = WARN, cactus.apache.cactus=false注:2、3、4所用的文件可以直接復制strutstest例子下的文件,然后進行修改。10配置strutstest包配置strutstest包 11CactusStrutsTestCase的繼承關系CactusStrutsTestCase - ServletTestCase - AbstractTestCase -TestCase12一個簡單的例子Public class LogonAction public ActionForward ex
13、ecute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) LogonActionForm actionForm=(LogonActionForm) form; String userName = actionForm.getUserName(); String password = actionForm.getPassword();if (AppLogic.doLogon(userName,password) return(actionMapp
14、ing.findForward(“success”);else return(actionMapping.findForward(“failed”); 13對應的actionformPublic class logonForm private String userName; private String password; public String getUserName() return this.userName; public String getPassword() return this.password; public void setUserName(String userN
15、ame) this.userName = userName; public void getPassword(String password) this.password = password; 14相對應的測試類public class LogonActionTest extends CactusStrutsTestCase /* 構造方法參數是必須的,在用TestSuite進行集合測試時需要*/ public LogonActionTest (String testName) super(testName); public void setUp() throws Exception super.setUp(); public void tearDown() throws Exception super.tearDown(); 15 /*以下為實現一條測試用例的方法*/ public void testLogonSuccessful () setRequestPathInfo(/logonAction); addRequestParameter(“userName, “zhangq”); addRequestParameter(password, “zhangq
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 購物中心電動汽車充電服務考核試卷
- 風景區(qū)旅游市場營銷策略與實施考核試卷
- 塑料薄膜在運動器材領域的應用考核試卷
- 其他文教辦公用品制造考核試卷
- 金屬制品行業(yè)科技創(chuàng)新與產業(yè)政策研究考核試卷
- 鋅錳電池關鍵性能參數檢測方法考核試卷
- 2024年度貴州省安全員之B證(項目負責人)模擬考核試卷含答案
- 2024年度貴州省安全員之A證(企業(yè)負責人)練習題及答案
- 2024年度甘肅省安全員之B證(項目負責人)考前沖刺試卷A卷含答案
- 河北省農業(yè)承包合同(2篇)
- 2024年新人教版數學七年級上冊教學課件 4.2 第2課時 去括號
- 網絡游戲平臺開發(fā)及運營合作協(xié)議
- 2024新湘教版初中七年級數學上冊第四章圖形的認識大單元整體教學設計
- DB3301∕T 65.1-2024 反恐怖防范系統(tǒng)管理規(guī)范 第1部分:通則
- 貓砂產品市場需求分析報告
- 2024至2030年中國金屬鉬行業(yè)應用現狀及投資發(fā)展前景展望分析報告
- 天燃氣工程管道施工組織設計及方案2
- 《列車運行管理與安全》全套教學課件
- 2024至2030年全球與中國市場硫酸銨深度研究報告
- 2024-2030年中國補鋰劑市場產銷需求與投資前景分析報告
- 教師青藍工程工作計劃
評論
0/150
提交評論