利用JUnit及STC進(jìn)行單體測試二_第1頁
利用JUnit及STC進(jìn)行單體測試二_第2頁
利用JUnit及STC進(jìn)行單體測試二_第3頁
利用JUnit及STC進(jìn)行單體測試二_第4頁
利用JUnit及STC進(jìn)行單體測試二_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、Beyond TechnologyJUnit及STC進(jìn)行單體測試(二)(Ver1.0)1目的與目標(biāo)StrutsTestCase for JUnit介紹STC提供的兩種測試方式STC的配置使用STC示例2課程概述實(shí)際項(xiàng)目需要JUnit的不足STC的優(yōu)勢3StrutsTestCase for JUnit4StrutsTestCase提供的兩種途徑采用模擬對象途徑采用Cactus來真實(shí)的運(yùn)行Struts的ActionServlet5Cactus測試框架的配置修改web.xml文件建立perties文件 指定日志文件配置strutstest包6修改web.xml文件a. 增加一個(gè)filter Filt

2、erRedirector org.apache.cactus.server.FilterTestRedirector 增加相應(yīng)的filter mapping FilterRedirector /FilterRedirector b. 增加兩個(gè)servlet JspRedirector jsp- ServletRedirector org.apache.cactus.server.ServletTestRedirector 增加相應(yīng)的servlet mapping JspRedirector /JspRedirector ServletRedirector /ServletRedirector

3、7建立perties文件在當(dāng)前工程文件夾下的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 端口號應(yīng)寫實(shí)際你所使用的端口號。8建立log_perties文件在當(dāng)前工程文件夾下的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 指定日志文件的位置與名稱,如果指定的文件夾不存在,則會(huì)自動(dòng)創(chuàng)建。9建立log_perties文件在當(dāng)前工程文件夾下的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所用的文件可以直接復(fù)制strutstest例子下的文件,然后進(jìn)行修改。10配置strutstest包配置strutstest包 11CactusStrutsTestCase的繼承關(guān)系CactusStrutsTestCase - ServletTestCase - AbstractTestCase -TestCase12一個(gè)簡單的例子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對應(yīng)的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相對應(yīng)的測試類public class LogonActionTest extends CactusStrutsTestCase /* 構(gòu)造方法參數(shù)是必須的,在用TestSuite進(jìn)行集合測試時(shí)需要*/ public LogonActionTest (String testName) super(testName); public void setUp() throws Exception super.setUp(); public void tearDown() throws Exception super.tearDown(); 15 /*以下為實(shí)現(xiàn)一條測試用例的方法*/ public void testLogonSuccessful () setRequestPathInfo(/logonAction); addRequestParameter(“userName, “zhangq”); addRequestParameter(password, “zhangq”); ac

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論