




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
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,內(nèi)容如下:# 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,內(nèi)容如下:# 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,內(nèi)容如下:# 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 /* 構(gòu)造方法參數(shù)是必須的,在用TestSuite進行集合測試時需要*/ public LogonActionTest (String testName) super(testName); public void setUp() throws Exception super.setUp(); public void tearDown() throws Exception super.tearDown(); 15 /*以下為實現(xiàn)一條測試用例的方法*/ public void testLogonSuccessful () setRequestPathInfo(/logonAction); addRequestParameter(“userName, “zhangq”); addRequestParameter(password, “zhangq
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- UX 設計師崗位面試問題及答案
- 2025屆河北省秦皇島市一中高二下化學期末教學質(zhì)量檢測試題含解析
- 2025屆天津市靜海區(qū)獨流中學化學高二下期末調(diào)研試題含解析
- 村鎮(zhèn)園林項目管理辦法
- 華為運動啟動管理辦法
- 華潤燃氣績效管理辦法
- 農(nóng)村代理記賬管理辦法
- 公共綠化區(qū)域管理辦法
- 檢察檔案保密管理辦法
- 多功能復合創(chuàng)可貼-洞察及研究
- 新課標(水平三)體育與健康《籃球》大單元教學計劃及配套教案(18課時)
- GB/T 44910-2024琥珀分級
- 臨時施工出入口交通疏導方案
- 醫(yī)療設備器材供貨安裝、調(diào)試及售后服務方案
- 大學生創(chuàng)新創(chuàng)業(yè)基礎(創(chuàng)新創(chuàng)業(yè)課程)完整全套教學課件
- 部編版語文三年級上冊第四單元教材解讀大單元集體備課
- 《論語十二章》挖空練習及答案
- 一對一幫扶協(xié)議書范本
- 2024年江蘇省無錫市中考英語試卷真題(含答案解析)
- 網(wǎng)絡安全設備巡檢記錄表
- 反假幣題庫(484道)
評論
0/150
提交評論