﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Skynet-随笔分类-JUnit</title><link>http://www.blogjava.net/Good-Game/category/23016.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 06 Mar 2008 07:59:02 GMT</lastBuildDate><pubDate>Thu, 06 Mar 2008 07:59:02 GMT</pubDate><ttl>60</ttl><item><title>httpUnit 之使用其他web资源</title><link>http://www.blogjava.net/Good-Game/archive/2008/01/29/178388.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 29 Jan 2008 09:25:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2008/01/29/178388.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/178388.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2008/01/29/178388.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/178388.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/178388.html</trackback:ping><description><![CDATA[
		<br />httpUnit<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> httpUnit;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.GetMethodWebRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebConversation;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebForm;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebResponse;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HttpTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase {<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testT() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        WebConversation wc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> WebConversation();<br />        WebRequest     req </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> GetMethodWebRequest( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://www.baidu.com</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br />        <br />        WebResponse   resp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> wc.getResponse( req );<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&lt;input type=submit value=百度一下 id=sb&gt;<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&lt;input type=text name=wd id=kw size=36 maxlength=100&gt;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        WebForm form </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> resp.getForms()[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">];      </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> select the first form in the page</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        form.setParameter( </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">wd</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Italian</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );   <br />        resp.getForms()[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">].getSubmitButtonWithID(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sb</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).click();<br /><br />        System.out.println( wc.getCurrentPage().getText() );<br />    }<br />}</span></div><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/178388.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2008-01-29 17:25 <a href="http://www.blogjava.net/Good-Game/archive/2008/01/29/178388.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>不使用容器 进行 测试 jsp </title><link>http://www.blogjava.net/Good-Game/archive/2007/11/02/157794.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 02 Nov 2007 09:11:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/11/02/157794.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/157794.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/11/02/157794.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/157794.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/157794.html</trackback:ping><description><![CDATA[参照：<a href="http://blog.csdn.net/rmartin/archive/2007/05/21/1618872.aspx">容器外的JSP页面测试技术</a><br />由于上面给出例 复杂 。一般人很难理解。我也是 ^_^<br />但仔细看我还是自己写出一个比较简单的，望大家一起讨论。<br /><br /><font color="#ffa500"><b>被测试jsp <br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">&lt;%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@ taglib prefix</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">html</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"> uri</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">/WEB-INF/struts-html.tld</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"> </span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">&lt;%</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">@ taglib prefix</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">c</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"> uri</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">=</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">/WEB-INF/c-1_0-rt.tld</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);">"</span><span style="background-color: rgb(245, 245, 245); color: rgb(0, 0, 0);"> </span><span style="background-color: rgb(255, 255, 0); color: rgb(0, 0, 0);">%&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html:html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">c:if </span><span style="color: rgb(255, 0, 0);">test</span><span style="color: rgb(0, 0, 255);">="${name != pass}"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />       ${name}  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />       ${pass} </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">&gt;<br />       <font color="#ffa500">&lt;!-- &lt;html:text property="in" &gt;&lt;/html:text&gt; --&gt;</font><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">c:if</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html:html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /></b><br /></font><br /><br /><br /><font color="#ffa500"><b>ant</b><font color="#000000">直接把他放在 eclipes 工程的根目录下 <b>build.xml<br />    </b>但有有3个参数要设置 tomcat.home  Tomcat 的地址 <br />                        webapp.path 工程中的根目录，下面有WEB-INF<br />                        src 原代码 （到时候jsp会翻译成.java <br />                                    到这个目录的 org.apache.jsp.jsp 下）<br /></font><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">project </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="Webapp Precompilation"</span><span style="color: rgb(255, 0, 0);"> default</span><span style="color: rgb(0, 0, 255);">="all"</span><span style="color: rgb(255, 0, 0);"> basedir</span><span style="color: rgb(0, 0, 255);">="."</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br /><br />  </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> tomcat dir </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="tomcat.home"</span><span style="color: rgb(255, 0, 0);"> value</span><span style="color: rgb(0, 0, 255);">="D:\Tomcat 5.0"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />  <br />  </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> this=..//WEB-INF (in eclipes)  </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="webapp.path"</span><span style="color: rgb(255, 0, 0);"> value</span><span style="color: rgb(0, 0, 255);">=".\WebRoot"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);"> src (in eclipes) </span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="src"</span><span style="color: rgb(255, 0, 0);"> value</span><span style="color: rgb(0, 0, 255);">="./src"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">target </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="jspc"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">taskdef </span><span style="color: rgb(255, 0, 0);">classname</span><span style="color: rgb(0, 0, 255);">="org.apache.jasper.JspC"</span><span style="color: rgb(255, 0, 0);"> name</span><span style="color: rgb(0, 0, 255);">="jasper2"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpath </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="jspc.classpath"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">pathelement </span><span style="color: rgb(255, 0, 0);">location</span><span style="color: rgb(0, 0, 255);">="${java.home}/../lib/tools.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/bin"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/server/lib"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/common/lib"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">taskdef</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br /><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">jasper2 <br />             </span><span style="color: rgb(255, 0, 0);">validateXml</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"> <br />             uriroot</span><span style="color: rgb(0, 0, 255);">="${webapp.path}"</span><span style="color: rgb(255, 0, 0);"> <br />             webXmlFragment</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/generated_web.xml"</span><span style="color: rgb(255, 0, 0);"> <br />             outputDir</span><span style="color: rgb(0, 0, 255);">="${src}"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"> <br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">target</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">target </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="compile"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">mkdir </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/classes"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">mkdir </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/lib"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">javac </span><span style="color: rgb(255, 0, 0);">destdir</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/classes"</span><span style="color: rgb(255, 0, 0);"><br />           optimize</span><span style="color: rgb(0, 0, 255);">="off"</span><span style="color: rgb(255, 0, 0);"><br />           debug</span><span style="color: rgb(0, 0, 255);">="on"</span><span style="color: rgb(255, 0, 0);"> failonerror</span><span style="color: rgb(0, 0, 255);">="false"</span><span style="color: rgb(255, 0, 0);"><br />           srcdir</span><span style="color: rgb(0, 0, 255);">="${src}"</span><span style="color: rgb(255, 0, 0);"> <br />       excludes</span><span style="color: rgb(0, 0, 255);">="**/*.smap"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">pathelement </span><span style="color: rgb(255, 0, 0);">location</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/classes"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/lib"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">pathelement </span><span style="color: rgb(255, 0, 0);">location</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/common/classes"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/common/lib"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">pathelement </span><span style="color: rgb(255, 0, 0);">location</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/shared/classes"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/shared/lib"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${tomcat.home}/bin"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />          </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="*.jar"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"> <br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fileset</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> <br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">classpath</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">include </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="**"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">exclude </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="tags/**"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">javac</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">target</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">target </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="all"</span><span style="color: rgb(255, 0, 0);"> depends</span><span style="color: rgb(0, 0, 255);">="jspc,compile"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">target</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">target </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="cleanup"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">delete</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/src"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fileset </span><span style="color: rgb(255, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">="${webapp.path}/WEB-INF/classes/org/apache/jsp"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />      </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">delete</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">target</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">project</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br /><b>TEST<br /></b><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> jetty.test.supper;<br /><br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletResponse;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.jsp.jsp.MyJsp_jsp;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.GetMethodWebRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebResponse;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.InvocationContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.ServletRunner;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.ServletUnitClient;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> JSPCTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase{<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> InvocationContext ic </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;<br /><br />    </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />        ServletRunner sr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ServletRunner();<br />           </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 向环境中注册 jsp </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        sr.registerServlet(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">HelloWorld</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, MyJsp_jsp.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">.getName());<br />        ServletUnitClient  sc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sr.newClient();<br />        WebRequest request </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> GetMethodWebRequest(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://localhost/HelloWorld</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />         ic </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sc.newInvocation(request);<br /><br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testJspC() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        HttpServletRequest re </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  ic .getRequest();<br />        HttpServletResponse rq </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  ic.getResponse();<br />        re.setAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">liukaiyi</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        re.setAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pass</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">123456</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        <br />        MyJsp_jsp is </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (MyJsp_jsp) ic.getServlet();<br />        is._jspService(re,rq);<br />        <br />        WebResponse response </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ic.getServletResponse();<br /><font color="#008000">// 输出</font><br />        System.out.println( response.getText() );<br />        <br />    }<br />}</span></div><b><br />结果是<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />       liukaiyi  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />       123456 </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    <br />    <br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br /><font color="#006400">后面用 HttpUnit 和 HtmlUnit 测试就不用我说了把 网上一大把。</font></b><br /><br /><br /><br /></font><img src ="http://www.blogjava.net/Good-Game/aggbug/157794.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-11-02 17:11 <a href="http://www.blogjava.net/Good-Game/archive/2007/11/02/157794.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>测试 WEB</title><link>http://www.blogjava.net/Good-Game/archive/2007/11/02/157726.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 02 Nov 2007 04:44:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/11/02/157726.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/157726.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/11/02/157726.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/157726.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/157726.html</trackback:ping><description><![CDATA[
		<p>
				<font color="#ffa500">
						<strong>
								<font color="#000000">学习测试留个印<br /></font>
								<br />
								<br />测试 Servlet 使用: </strong>
				</font>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<span style="color: rgb(0, 0, 255);">package</span>
				<span style="color: rgb(0, 0, 0);"> jetty.test.supper;<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> java.io.File;<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletRequest;<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> jetty.LoginServlet;<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.GetMethodWebRequest;<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebConversation;<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebRequest;<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebResponse;<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.InvocationContext;<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.ServletRunner;<br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.ServletUnitClient;<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">import</span>
				<span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /><br /></span>
				<span style="color: rgb(0, 0, 255);">public</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">class</span>
				<span style="color: rgb(0, 0, 0);"> HttpUnitTest </span>
				<span style="color: rgb(0, 0, 255);">extends</span>
				<span style="color: rgb(0, 0, 0);"> TestCase {<br />    </span>
				<span style="color: rgb(0, 0, 255);">public</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">void</span>
				<span style="color: rgb(0, 0, 0);"> ctestUrl()</span>
				<span style="color: rgb(0, 0, 255);">throws</span>
				<span style="color: rgb(0, 0, 0);"> Exception{<br />        System.out.println(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">直接获取网页内容：</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />        WebConversation wc </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> WebConversation();<br />        WebResponse wr </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> wc.getResponse( </span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">http://www.google.com</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);"> );<br />        System.out.println( wr.getText() );<br />    }<br />    <br />    </span>
				<span style="color: rgb(0, 0, 255);">public</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">void</span>
				<span style="color: rgb(0, 0, 0);"> testRun1()</span>
				<span style="color: rgb(0, 0, 255);">throws</span>
				<span style="color: rgb(0, 0, 0);"> Exception{<br />        System.out.println(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">无参数测试：</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">建立服务器</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        ServletRunner sr </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> ServletRunner(</span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> File(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">WebRoot\\WEB-INF\\test.xml</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">));<br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">模拟客户端</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        ServletUnitClient sc </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> sr.newClient();<br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">URL 定位</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        WebRequest request   </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> GetMethodWebRequest( </span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">http://localhost:7000/cactusDemo</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);"> );<br />        WebResponse response </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> sc.getResponse( request );<br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">运行</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        System.out.println(response.getText()</span>
				<span style="color: rgb(0, 0, 0);">+</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">\n</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />    }<br />    <br />    </span>
				<span style="color: rgb(0, 0, 255);">public</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">void</span>
				<span style="color: rgb(0, 0, 0);"> testRun2()</span>
				<span style="color: rgb(0, 0, 255);">throws</span>
				<span style="color: rgb(0, 0, 0);"> Exception{<br />        System.out.println(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">Session 和 request 测试：</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />        ServletRunner sr </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> ServletRunner(</span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> File(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">WebRoot\\WEB-INF\\test.xml</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">));<br />        ServletUnitClient sc </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> sr.newClient();<br />        WebRequest request   </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> </span>
				<span style="color: rgb(0, 0, 255);">new</span>
				<span style="color: rgb(0, 0, 0);"> GetMethodWebRequest( </span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">http://localhost/cactusDemo</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);"> );<br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">Parameter 加参 use </span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        request.setParameter(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">use</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">,</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">web</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />        <br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">取出 Servlet : LoginServlet 方法准备执行</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        InvocationContext ic </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> sc.newInvocation( request );<br />        LoginServlet se </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> (LoginServlet)ic.getServlet();<br />        HttpServletRequest re </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> ic.getRequest() ;<br /><br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">request session  加参 use </span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        re.setAttribute(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">use</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">,</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">re</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br />        re.getSession(</span>
				<span style="color: rgb(0, 0, 255);">true</span>
				<span style="color: rgb(0, 0, 0);">).setAttribute(</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">use</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">,</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">re</span>
				<span style="color: rgb(0, 0, 0);">"</span>
				<span style="color: rgb(0, 0, 0);">);<br /><br />        se.doGet(re,ic.getResponse());</span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">关键：运行测试方法<br />        <br />        </span>
				<span style="color: rgb(0, 128, 0);">//</span>
				<span style="color: rgb(0, 128, 0);">获取 out</span>
				<span style="color: rgb(0, 128, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 0);">        WebResponse response </span>
				<span style="color: rgb(0, 0, 0);">=</span>
				<span style="color: rgb(0, 0, 0);"> ic.getServletResponse();<br />        System.out.println(response.getText());<br />    }<br />}<br /></span>
		</div>
		<p>test.xml</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<span style="color: rgb(0, 0, 255);">&lt;?</span>
				<span style="color: rgb(255, 0, 255);">xml version="1.0" encoding="UTF-8"</span>
				<span style="color: rgb(0, 0, 255);">?&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">web-app </span>
				<span style="color: rgb(255, 0, 0);">xmlns</span>
				<span style="color: rgb(0, 0, 255);">="http://java.sun.com/xml/ns/j2ee"</span>
				<span style="color: rgb(255, 0, 0);"> xmlns:xsi</span>
				<span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span>
				<span style="color: rgb(255, 0, 0);"> version</span>
				<span style="color: rgb(0, 0, 255);">="2.4"</span>
				<span style="color: rgb(255, 0, 0);"> xsi:schemaLocation</span>
				<span style="color: rgb(0, 0, 255);">="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />  </span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">servlet</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />    </span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">servlet-name</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">cactusDemo</span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">servlet-name</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />    </span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">servlet-class</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">jetty.LoginServlet</span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">servlet-class</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />  </span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">servlet</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />
						<br />  </span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">servlet-mapping</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />    </span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">servlet-name</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">cactusDemo</span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">servlet-name</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />    </span>
				<span style="color: rgb(0, 0, 255);">&lt;</span>
				<span style="color: rgb(128, 0, 0);">url-pattern</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">/cactusDemo</span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">url-pattern</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />  </span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">servlet-mapping</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
				<span style="color: rgb(0, 0, 0);">
						<br />
				</span>
				<span style="color: rgb(0, 0, 255);">&lt;/</span>
				<span style="color: rgb(128, 0, 0);">web-app</span>
				<span style="color: rgb(0, 0, 255);">&gt;</span>
		</div>
		<p>
				<font color="#0000ff">
				</font>
				<br />
				<font color="#ffa500">
						<strong>测试 JSP:<br /></strong>
						<a href="http://httpunit.sourceforge.net/doc/cookbook.html">Cookbook</a>
						<font color="#000000">参考</font> <br /></font>
				<a id="Editor_Results_rprSelectionList_ctl01_LinkTitle" class="titlelink" href="/Good-Game/archive/2007/11/02/157794.html">不使用容器 进行 测试 jsp</a>
				<br />
		</p>
		<p>
				<font color="#ffa500">
						<strong>测试Struts:<br /></strong>
						<a class="singleposttitle" id="viewpost1_TitleUrl" href="/Good-Game/archive/2007/04/16/110991.html">
								<strong>StrutsTestCase </strong>
						</a>
						<font color="#000000">参考</font> <br /></font>
		</p>
<img src ="http://www.blogjava.net/Good-Game/aggbug/157726.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-11-02 12:44 <a href="http://www.blogjava.net/Good-Game/archive/2007/11/02/157726.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>测试 servlet(转)</title><link>http://www.blogjava.net/Good-Game/archive/2007/10/31/157141.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Wed, 31 Oct 2007 03:11:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/10/31/157141.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/157141.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/10/31/157141.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/157141.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/157141.html</trackback:ping><description><![CDATA[1. HttpUnit<br /><div>1&gt;servlet可以脱离容器，容易把该测试写入ant或maven脚本，让测试进行。<br />2&gt;<font face="Times New Roman">httpunit在测试servlet行为时，采用的是完全模拟浏览器，有时测试比较难写。</font></div><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> Cactus.test.support;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> Cactus.HelloWorld;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.GetMethodWebRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebResponse;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.InvocationContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.ServletRunner;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.servletunit.ServletUnitClient;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.Assert;<br /> <br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> HttpUnitTestHelloWorld </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase {<br /> <br /> </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />  </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();<br /> }<br /> <br /> </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> tearDown() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />  </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.tearDown();<br /> }<br /> <br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testHelloWorld() {<br />  <br />  </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /><br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 创建Servlet的运行环境</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br />   ServletRunner sr </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ServletRunner();<br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 向环境中注册Servlet</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">   sr.registerServlet(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">HelloWorld</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, HelloWorld.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">.getName());<br /> <br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 创建访问Servlet的客户端</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br />   ServletUnitClient sc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sr.newClient();<br /><br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 发送请求</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br />   WebRequest request </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> GetMethodWebRequest(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://localhost/HelloWorld</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />   request.setParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">username</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">testuser</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />   <br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">用委托加载 is</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">   InvocationContext ic </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sc.newInvocation(request);<br />   HelloWorld is </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (HelloWorld) ic.getServlet();<br /> <br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 测试servlet的某个方法</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">   Assert.assertTrue(is.authenticate());<br /><br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 获得模拟服务器的信息</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">   WebResponse response </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sc.getResponse(request);<br /><br />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 断言</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">   Assert.assertTrue(response.getText().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">testuser:Hello World!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /><br />  } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Exception e) {<br /><br />   e.printStackTrace();<br /><br />  }<br /><br /> }<br /> <br />}</span></div><br /><br />Jetty<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> Cactus.test.support;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.mortbay.jetty.Connector;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.mortbay.jetty.Server;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.mortbay.jetty.bio.SocketConnector;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.mortbay.jetty.servlet.ServletHandler;<br /> <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebConversation;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.meterware.httpunit.WebResponse;<br /> <br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.Assert;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /> <br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> JettySampleTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TestCase {<br /> <br /> Server server;<br /> </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />      </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">通过代码设置并启动一个服务器，该服务器是servlet的测试容器</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();<br />      server </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Server();<br />      Connector connector</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SocketConnector();<br />      connector.setPort(</span><span style="color: rgb(0, 0, 0);">80</span><span style="color: rgb(0, 0, 0);">);<br />      server.setConnectors(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Connector[]{connector});<br />      ServletHandler handler</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ServletHandler();<br />      server.setHandler(handler);<br />      handler.addServletWithMapping(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Cactus.HelloWorld</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />      server.start();<br /> }<br /> <br /> </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> tearDown() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />  </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.tearDown();<br />  server.stop();<br /> }<br /> <br /> </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testHellWorld() {<br />  </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />   WebConversation wc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> WebConversation();<br />   WebResponse web </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> wc.getResponse(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://127.0.0.1/HelloWorld</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />   String result</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">web.getText();<br />   Assert.assertEquals(result,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">null:Hello World!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />  <br />  } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Exception e) {<br />   e.printStackTrace();<br />  }<br /> }<br />}</span></div><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/157141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-10-31 11:11 <a href="http://www.blogjava.net/Good-Game/archive/2007/10/31/157141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>junit 笔记</title><link>http://www.blogjava.net/Good-Game/archive/2007/10/30/157007.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 30 Oct 2007 09:59:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/10/30/157007.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/157007.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/10/30/157007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/157007.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/157007.html</trackback:ping><description><![CDATA[参考：http://caterpillar.onlyfun.net/GossipCN/JUnit/JUnitGossip.htm <br /><br />1. TestSuite<br /><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">  public static Test suite() {</span><br style="font-weight: bold; font-family: Courier New,Courier,monospace;" /><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">     </span></small><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">TestSuite </span></small><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;"></span></small><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">suite </span></small><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">= </span></small><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">new TestSuite(MathTool.class);<br />     </span></small><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;">suite.addTest(new MathToolTest("testGcd"));</span></small><br style="font-weight: bold; font-family: Courier New,Courier,monospace;" /><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;"></span>  <span style="font-weight: bold; font-family: Courier New,Courier,monospace;">}<br /><br /></span></small><pre>2.全局属性<br />    protected void setUp() throws Exception {<br />        super.setUp();<br />        arr = new ............;<br />    }<br /><br />    protected void tearDown() throws Exception {<br />        super.tearDown();<br />        arr = null;<br />    }<br /><br />3. Cactus<br />web设置 <br /><br />http://caterpillar.onlyfun.net/GossipCN/JUnit/FirstCactusWithTomcat.htm<br />http://caterpillar.onlyfun.net/GossipCN/JUnit/FirstCactusWithJetty.htm<br /><br /><br /></pre><br /><small><span style="font-weight: bold; font-family: Courier New,Courier,monospace;"><br /><br /></span></small><img src ="http://www.blogjava.net/Good-Game/aggbug/157007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-10-30 17:59 <a href="http://www.blogjava.net/Good-Game/archive/2007/10/30/157007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在Junit中测试私有函数的方法（junit, private, method) （转）</title><link>http://www.blogjava.net/Good-Game/archive/2007/10/23/155223.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Tue, 23 Oct 2007 03:11:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/10/23/155223.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/155223.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/10/23/155223.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/155223.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/155223.html</trackback:ping><description><![CDATA[
		<span id="LblContent">eclipse中如何写一个测试私有方法的junit？<br />假设类Summer定义如下：<br /></span>public class Summer{<br />   private int <font color="#0000ff"><strong>methodone</strong></font>(<font color="#ff6600"><strong>String</strong></font> argsone){<br />      //method code<br />      .......<br />      return 4;<br />   }<br />}<br /><br />测试如下：<br />public class SummerTest extends TestCase {<br />   public void testMethodone(){<br />      Object rightResult = xxxxx;<br />      Summer example = new Summer.newInstance();<br />      Method m = example .getClass()<font color="#ff0000">.getDeclaredMethod</font>("<font color="#0000ff">methodone</font>",new Class[]{<font color="#ff6600">String.class</font>});<br />      <font color="#ff0000">m.setAccessible(true);</font><br />      Object result = m.invoke(example ,new Object[] {new String(xxxx)});<br />      m.setAccessible(false);<br />      if (result.equals(rightResult)){<br />         //your code<br />         ......<br />      }<br />   }<br />}<img alt="" src="/oceanqtt/aggbug/13798.html" height="1" width="1" /><img src ="http://www.blogjava.net/Good-Game/aggbug/155223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-10-23 11:11 <a href="http://www.blogjava.net/Good-Game/archive/2007/10/23/155223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>StrutsTestCase 不需要 写 classpath 方法   ^_^</title><link>http://www.blogjava.net/Good-Game/archive/2007/04/16/110991.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Mon, 16 Apr 2007 08:01:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/04/16/110991.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/110991.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/04/16/110991.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/110991.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/110991.html</trackback:ping><description><![CDATA[
		<b>		下载http://sourceforge.net/projects/strutstestcase/</b>
		<br />
		<b>
				<font color="#ff0000">
						<i>struts-config.xml</i>
				</font>
				<br />
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 0, 0);">&lt;?</span>
						<span style="color: rgb(0, 0, 0);">xml version</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">1.0</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> encoding</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">UTF-8</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">?&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
						</span>
						<span style="color: rgb(0, 0, 0);">&lt;!</span>
						<span style="color: rgb(0, 0, 0);">DOCTYPE struts</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">config PUBLIC </span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">-//Apache Software Foundation//DTD Struts Configuration 1.1//EN</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />
						</span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">struts</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">config</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">data</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">sources </span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">form</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">beans </span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">form</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">bean name</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">loginForm</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> type</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">com.yourcompany.struts.form.LoginForm</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;/</span>
						<span style="color: rgb(0, 0, 0);">form</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">beans</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">global</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">exceptions </span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">global</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">forwards </span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">action</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">mappings </span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />    </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">action<br />      name</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">loginForm</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      path</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">/login</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      scope</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">request</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      type</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">com.yourcompany.struts.action.LoginAction</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">forward<br />        name</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">ok</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        path</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">/form/suss.jsp</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />      </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">forward<br />        name</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">error</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">
								<br />        path</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">/form/login.jsp</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />         <br />    </span>
						<span style="color: rgb(0, 0, 0);">&lt;/</span>
						<span style="color: rgb(0, 0, 0);">action</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;/</span>
						<span style="color: rgb(0, 0, 0);">action</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">mappings</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />  </span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">message</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">resources parameter</span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);">com.yourcompany.struts.ApplicationResources</span>
						<span style="color: rgb(0, 0, 0);">"</span>
						<span style="color: rgb(0, 0, 0);"> </span>
						<span style="color: rgb(0, 0, 0);">/&gt;</span>
						<span style="color: rgb(0, 0, 0);">
								<br />
						</span>
						<span style="color: rgb(0, 0, 0);">&lt;/</span>
						<span style="color: rgb(0, 0, 0);">struts</span>
						<span style="color: rgb(0, 0, 0);">-</span>
						<span style="color: rgb(0, 0, 0);">config</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
				</div>
				<font color="#ff0000">Action<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">Created by MyEclipse Struts<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xsl</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com.yourcompany.struts.action;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletRequest;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletResponse;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.Action;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionForm;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionForward;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionMapping;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.yourcompany.struts.form.LoginForm;<br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> <br /> * MyEclipse Struts<br /> * Creation date: 04-16-2007<br /> * <br /> * XDoclet definition:<br /> * @struts.action path="/login" name="loginForm" input="/form/login.jsp" scope="request" validate="true"<br /> * @struts.action-forward name="Myjsp" path="/WEB-INF/"<br /> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> LoginAction </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> Action {<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> --------------------------------------------------------- Instance Variables<br /><br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> --------------------------------------------------------- Methods</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> <br />     * Method execute<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> mapping<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> form<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> request<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> response<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"> ActionForward<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> ActionForward execute(<br />        ActionMapping mapping,<br />        ActionForm form,<br />        HttpServletRequest request,<br />        HttpServletResponse response) {<br />        LoginForm loginForm </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (LoginForm) form;<br />        <br />        String name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> loginForm.getName() ;<br />        String pass </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> loginForm.getPass() ;<br />        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(name.equals(pass)){<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> mapping.findForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">login</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />            }<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> mapping.findForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ok</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />         <br />    }<br /><br />}<br /><br /></span></div><br />Form<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com.yourcompany.struts.form;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionErrors;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionForm;<br /><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> LoginForm </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> ActionForm {<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String name ;<br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String pass ;<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setName(String name){<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> name ;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> String getName(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.name ;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setPass(String pass){<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.pass </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pass ;<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> String getPass(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.pass ;<br />    }<br />}</span></div><br />关键的来了 ----
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.File;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> servletunit.struts.MockStrutsTestCase;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> junit.framework.TestCase;<br /></span><span style="color: rgb(0, 128, 0);">//<br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> StrutsTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> MockStrutsTestCase {<br /><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> StrutsTest(String testName){<br />        </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">(testName);<br />    }<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{<br />        </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();<br />          File web </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">E:/src/StrutsTestCase/WebRoot/</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.setContextDirectory(web);<br />        setConfigFile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">E:/src/StrutsTestCase/WebRoot/WEB-INF/web.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        setConfigFile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">E:/src/StrutsTestCase/WebRoot/WEB-INF/struts-config.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /> </span><span style="color: rgb(0, 0, 0);"><br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testAction() {<br />        </span><b><font size="-0"><b><font color="#ff0000"><span style="color: rgb(0, 0, 0);">setRequestPathInfo(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/login</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span></font></b></font></b><br /><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">liu</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pass</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">123</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        actionPerform();<br />        </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.verifyForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ok</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br />不需要 写 classpath 哈哈<br /></font>
		</b>
<img src ="http://www.blogjava.net/Good-Game/aggbug/110991.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-04-16 16:01 <a href="http://www.blogjava.net/Good-Game/archive/2007/04/16/110991.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>